9

使用prometheus的azure_sd_config自动添加azure云主机到监控

 3 years ago
source link: https://www.bboy.app/2021/08/26/%E4%BD%BF%E7%94%A8prometheus%E7%9A%84azure_sd_config%E8%87%AA%E5%8A%A8%E6%B7%BB%E5%8A%A0azure%E4%BA%91%E4%B8%BB%E6%9C%BA%E5%88%B0%E7%9B%91%E6%8E%A7/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

使用prometheus的azure_sd_config自动添加azure云主机到监控

发表于

2021-08-26 分类于 prometheus

202108261713945.png

监控最头疼的就是添加新加的机器了,所以如何自动化添加机器就成了话题,一般大家会使用consul,当一台机器启动之后可以自动向consul去注册自己,然后添加到监控系统中,prometheus原生提供了azure_sd_config去主动发现azure中的机器

首先你要在Azure Active Directory中应用注册里面新注册一个prometheus的应用,然后在每个订阅的访问控制中把这个应用添加为读者权限

之后创建这个应用的客户端密码记录下客户端密码的值

接着配置prometheus

- job_name: 'azure_windows_node'
azure_sd_configs:
- subscription_id: 123
environment: AzureChinaCloud
tenant_id: 123
client_id: 123
client_secret: 123
refresh_interval: 600s

relabel_configs:
- source_labels: ['__meta_azure_machine_tag_public_ip']
regex: (.+)
target_label: __address__
replacement: "$1:9182"
- source_labels: ['__meta_azure_machine_name']
target_label: instance
- source_labels: ['__meta_azure_machine_tag_stop']
regex: "true"
action: drop
- source_labels: ['__meta_azure_machine_os_type']
regex: "Linux"
action: drop

解释下参数

  • subscription_id 你的订阅id
  • environment 这个表示你的azure的地区,比如中国特色的azure就是写AzureChinaCloud,如果是全球地区的可以不用写
  • tenant_id 租户id
  • client_id prometheus的应用id
  • client_secret 就是刚才创建的prometheus的secret
  • refresh_interval 刷新时间,个人建议稍微时间长一点

relabel_configs 里面要注意一下我不知道为什么我获取不到publicip,所有的__address__都是内网ip,所以这个时候你就需要给每个虚拟机都打一个tag public_ip来relabel成address

当然你的主机不一定都是启动的也有可能是关闭的,所以可以把你关闭的主机打一个stop的标签来过滤掉

然后还有一个点是,如果你的虚拟机是比较多的,而且有windows和linux你也可以使用label去分组

如果配置都是对的话那么一般不会有什么其他的问题

欢迎关注我的博客www.bboy.app

Have Fun

欢迎关注我的其它发布渠道


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK