官方文档
https://github.com/prometheus/consul_exporter
1、编译运行
# 获取方式1go get github.com/prometheus/consul_exportercd ${GOPATH-/root/go}/src/github.com/prometheus/consul_exporter make# 获取方式2mkdir -p ${GOPATH:-/root/go}cd ${GOPATH:-/root/go}mkdir -p $GOPATH/src/github.com/prometheuscd $GOPATH/src/github.com/prometheus git clone https://github.com/prometheus/consul_exporter.gitcd ${GOPATH:-/root/go}go install github.com/prometheus/consul_exporter# 正常情况下现在应该编译成功了ll bin/consul_exporter# 查看帮助./bin/consul_exporter --help
使用docker
docker pull prom/consul-exporter docker run -d -p 9107:9107 prom/consul-exporter --consul.server=172.17.0.1:8500
2、常用参数
--consul.allow_stale 允许非leader consul server 提供读服务 --web.listen-address=":9107" 设置监听的地址和端口,默认9107 --consul.health-summary 为每个服务身体差一个健康summary。需要n+1次查询来收集所有的信息 --consul.server="http://localhost:8500" 指定consul服务器地址
没有提供token 的选项,但是支持CONSUL_HTTP_TOKEN 等环境变量
3、暴露的metrics
Metric | Meaning | Labels |
---|---|---|
consul_up | 最后一次查询consul是否成功 | |
consul_raft_peers | How many peers (servers) are in the Raft cluster | |
consul_serf_lan_members | How many members are in the cluster | |
consul_health_node_status | 节点的健康状态 | check, node, status |
consul_catalog_services | 集群中有多少服务 | |
consul_catalog_service_node_healthy | 指定节点上的服务是否健康 | service, node |
consul_health_service_status | 指定服务的健康检查 | check, node, service, status |
consul_catalog_kv | 指定key的value ,key的值如果不是数字的话,会被忽略 | key |
4、一些有用的查询
Are my services healthy?
min(consul_catalog_service_node_healthy) by (service_name)
值为1 表示服务的所有实例都是健康的。0表示至少有一个是不健康的
What service nodes are failing?
sum by (node, service_name)(consul_catalog_service_node_healthy == 0)
What service checks are critical?
consul_health_service_status{status="critical"} == 1
除了critical
之外,你还可以查询其他状态: "maintenance", "critical", "warning" or "passing"
作者:坚持到底v2
链接:https://www.jianshu.com/p/b885ba36992a
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。