prometheus+consul 動態注冊+blackbox_exporter


首先為啥用consul動態注冊

1.這個有健康檢測,可以檢測exporter的狀態,

2.避免頻繁的修改prometheus配置文件,方便管理

3.consul可以做集群避免單點故障

這里就用blackbox_exporter+consul+prometheus+grafana

一。安裝blackbox_exporter

在我的隨筆里面有百度雲鏈接 https://www.cnblogs.com/lc226/p/11222048.html

1.下載解壓后 nohup ./blackbox_exporter  &

2.查看輸出結果  tail -f nohup.out 

二.配置prometheus,yml,注意格式

- job_name: http_2xx
params:
module:
- http_2xx
scrape_interval: 2s
scrape_timeout: 2s
metrics_path: /probe
consul_sd_configs:
- server: localhost:8500
tag_separator: ','
services:
- http_2xx
relabel_configs:
- source_labels: ['__address__']
target_label: __param_target
- source_labels: ['__meta_consul_service_address']
target_label: instance
- target_label: __address__
replacement: localhost:9115

3。重啟prometheus

 

 

三。安裝consul

1.解壓后就一個consul程序,然后直接 用server模式

nohup ./consul agent -server -bootstrap-expect=1 -data-dir=/home/date -node=server-110 -bind=172.16.16.80 -client 0.0.0.0 -ui &

 

 注冊blackbox_exporter

這里有兩種方式,

1.是建立json文件(以后有空再介紹)

2.通過consul提供的httpAPI接口注冊。接口是:http://localhost:8500/v1/agent/service/register

然后我們用api的方式注冊,並且用http_2xx模塊

curl -X PUT -d '{"id": "http_2xx","name": "http_2xx","address": "172.16.16.74","port": 80 ,"tags": ["node"],"checks": [{"http": "http://172.16.16.80:9115/","interval": "5s"}]}' http://localhost:8500/v1/agent/service/register

http://localhost:8500/v1/agent/service/register

 

 

 這里要注意ID是唯一標識,name要和prometheus.yml的services一樣的名字

3.檢測是否成功

1.curl http://localhost:8500/v1/catalog/service/http_2xx

 

 

 

 2通過prometheus查看 .http://172.16.16.80:9090/targets

 

 3.查看指標

 

 四。grafana展示

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM