官方文檔
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
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯繫作者獲得授權並註明出處。