prometheus 自动发现

 

目录

一:通过consul注册中心自动发现prometheus节点

1)部署consul集群

2)通过consul 的API数据写入数据

3)配置prometheus到consul的服务发现

二:通过file_sd_configs 配置文件自动注册


一:通过consul注册中心自动发现prometheus节点

1)部署consul集群

节点信息:

10.19.2.60 node1

10.19.2.61 node2

10.19.2.62 node3

#三个consul节点都要执行

cd /opt/consul
unzip consul_1.12.2_linux_amd64.zip

#创建consul数据目录
mkdir /data/consul -pv


#各consul节点分别执行启动命令
#启动consul服务
node1节点启动命令如下:

nohup ./consul agent -server -bootstrap -bind=10.19.2.60 -client=10.19.2.60 -data-dir=/data/consul -ui -node=10.19.2.60 &


node2节点启动命令如下:

nohup ./consul agent  -bind=10.19.2.61 -client=10.19.2.61 -data-dir=/data/consul -node=10.19.2.61 -join=10.19.2.60 &

node3节点启动命令如下:

nohup ./consul agent  -bind=10.19.2.62 -client=10.19.2.62 -data-dir=/data/consul -node=10.19.2.62 -join=10.19.2.60 &

2)通过consul 的API数据写入数据

#向consul 写入数据

curl -X PUT -d '{
    "id": "node-export-14-9",
    "name": "node-export-14-9",
    "address": "10.19.14.9",
    "port": 9100,
    "tags": [
        "node-exporter"
    ],
    "checks": [
        {
            "http": "http://10.19.14.9:9100/",
            "interval": "5s"
        }
    ]
}' http://10.19.2.60:8500/v1/agent/service/register



#向consul 删除数据

curl --request PUT http://10.19.2.60:8500/v1/agent/service/deregister/node-export-14-9



验证数据信息

 

3)配置prometheus到consul的服务发现

  - job_name: consul
    honor_labels: true
    metrics_path: /metrics
    scheme: http
    consul_sd_configs:
       - server: 10.19.2.60:8500
         services: []
       - server: 10.19.2.61:8500
         services: []
       - server: 10.19.2.62: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"
        action: drop

重启prometheus

systemctl restart prometheus

 

二:通过file_sd_configs 配置文件自动注册

#2.62上配置sd_config配置文件

vi /opt/prometheus/prometheus/file_sd/sd_my_server.json


[
  {
     "targets": ["10.19.14.21:9100", "10.19.14.22:9100", "10.19.14.22:8080", "10.19.14.21:8080", "10.19.14.21:30100"]
  }
]


#添加jod_name

  - job_name: "file_sd_config"
    file_sd_configs:
      - files:
        - /opt/prometheus/prometheus/file_sd/sd_my_server.json
        refresh_interval: 10s

#重启prometheus

systemctl restart prometheus

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值