关于prometheus:prometheus-consul-自动化配置

装置

docker run --restart=always --name consul -p 8500:8500 -v /home/consul/conf/:/consul/conf/ -v /home/consul/data/:/consul/data/ -d consul agent -server -ui -bind=0.0.0.0 -client=0.0.0.0 -bootstrap-expect=1

  • add
[root@prometheus_sh_01_10_23_1x_174 ~]# curl -X PUT -d '{"id": "node-exporter11-10.31.140.24","name": "node-exporter11-10.31.140.24","address": "10.31.1x.24","port": 9100,"Meta": {"service": "test_consule","instance_host": "10.31.1x.24"},"tags": ["test"],"checks": [{"http": "http://10.31.1x.24:9100/metrics", "interval": "15s"}]}' http://10.100.1x.55:8500/v1/agent/service/register
  • 查看
[root@prometheus_sh_01_10_23_1x_174 ~]# curl  http://10.100.140.55:8500/v1/agent/services
{"node-exporter":{"ID":"node-exporter","Service":"node-exporter11-10.23.140.174","Tags":["test"],"Meta":{"instance_host":"10.23.140.174","service":"test_consule"},"Port":9100,"Address":"10.23.140.174","TaggedAddresses":{"lan_ipv4":{"Address":"10.23.140.174","Port":9100},"wan_ipv4":{"Address":"10.23.140.174","Port":9100}},"Weights":{"Passing":1,"Warning":1},"EnableTagOverride":false,"Datacenter":"dc1"},"node-exporter11-10.31.1x.24":{"ID":"node-exporter11-10.31.140.24","Service":"node-exporter11-10.31.1x.24","Tags":["test"],"Meta":{"instance_host":"10.31.1x.24","service":"test_consule"},"Port":9100,"Address":"10.31.140.24","TaggedAddresses":{"lan_ipv4":{"Address":"10.31.1x.24","Port":9100},"wan_ipv4":{"Address":"10.31.1x.24","Port":9100}},"Weights":{"Passing":1,"Warning":1},"EnableTagOverride":false,"Datacenter":"dc1"}}[root@prometheus_sh_01_10_23_1x_174 ~]# 
[root@prometheus_sh_01_10_23_x40_174 ~]# 
  • 删除

curl -X PUT  http://10.100.1x.55:8500/v1/agent/service/deregister/node-exporter11-10.23.1x.174

vim prometheus.yml


  - job_name: 'consul-prometheus'
    consul_sd_configs:
      - server: '10.100.1x.55:8500'
        services: []
       
    relabel_configs:
      - source_labels: ['__meta_consul_tags']
        target_label: 'product'
      - source_labels: ['__meta_consul_dc']
        target_label: 'idc'
      - source_labels: ['__meta_consul_service']
        regex: "consul"  #匹配为"consul" 的service
        action: drop       # 执行的动作
      - source_labels: ['job']
        target_label: 'environment'
        regex:        '(.*)job'
        replacement:   '${1}'

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理