首先为啥用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展示