一 consul监控项
- Transaction timing
- Leadership changes
- Autopilot
- Garbage collection
二 consul服务监控
- File descriptors
- CPU usage
- Network activity
- Disk activity
- Memory usage
三 监控可用指标
官方地址:https://www.consul.io/docs/agent/telemetry
指标名称 |
描述 |
consul.kvs.apply |
测量完成 KV 存储更新所需的时间。 |
consul.txn.apply |
测量应用事务操作所花费的时间。 |
consul.raft.apply |
计算间隔内发生的 Raft 事务的数量。 |
consul.raft.commitTime |
测量将新条目提交到领导者上的 Raft 日志所需的时间。 |
consul.raft.leader.lastContact |
在检查其领导者租用时,测量自领导者最后一次能够联系跟随者节点以来的时间。 |
consul.raft.state.candidate |
当 Consul 服务器开始选举过程时增加。 |
consul.raft.state.leader |
当 Consul 服务器成为领导者时增加。 |
consul.autopilot.healthy |
跟踪本地服务器集群的整体健康状况。如果所有服务器都被自动驾驶仪认为是健康的,这将被设置为 1。如果有任何服务器不健康,这将是 0。 |
consul.autopilot.failure_tolerance |
跟踪本地服务器集群在继续运行时可能丢失的投票服务器数量。 |
consul.runtime.total_gc_pause_ns |
自 Consul 启动以来,stop-the-world 垃圾收集 (GC) 暂停消耗的纳秒数。 |
linux_sysctl_fs.file-nr |
主机上所有进程使用的文件句柄数。 |
linux_sysctl_fs.file-max |
可用文件句柄的总数。 |
cpu.user_cpu |
用户进程(例如 Vault 或 Consul)使用的 CPU 百分比。 |
cpu.iowait_cpu |
等待 I/O 任务完成所花费的 CPU 时间百分比。 |
net.bytes_recv |
每个网络接口上接收到的字节数。 |
net.bytes_sent |
每个网络接口上传输的字节数。 |
diskio.read_bytes |
从每个块设备读取的字节数。 |
diskio.write_bytes |
写入每个块设备的字节数。 |
diskio.read_time |
从磁盘读取所花费的时间,以累积毫秒为单位。 |
diskio.write_time |
写入磁盘所花费的时间,以累积毫秒为单位。 |
consul.runtime.alloc_bytes |
测量 Consul 进程分配的字节数。 |
consul.runtime.sys_bytes |
从操作系统获得的内存总字节数。 |
mem.total |
服务器上可用的物理内存 (RAM) 总量。 |
mem.used_percent |
正在使用的物理内存的百分比。 |
swap.used_percent |
正在使用的交换空间的百分比。 |
四 安装 consul exporter
4.1 下载并安装consul exporter
root@consul-01:~# wget https://github.com/prometheus/consul_exporter/releases/download/v0.7.1/consul_exporter-0.7.1.linux-amd64.tar.gz
root@consul-01:~# tar xf consul_exporter-0.7.1.linux-amd64 -C /usr/local
root@consul-01:~# ln -sv /usr/local/consul_exporter-0.7.1.linux-amd64 /usr/local/consul_exporter
4.2 consul exporter使用帮助
-h, --help #显示上下文相关的帮助(也可以尝试 --help-long 和 --help-man)。
--web.listen-address=":9107" #Address 侦听 Web 界面和遥测。
--web.telemetry-path="/metrics" #暴露指标的路径。
--consul.health-summary #为每个服务实例生成一个健康摘要。需要 n+1 个查询来收集所有信息。
--kv.prefix="" #Prefix 从中公开键/值对。
--kv.filter=".*" #Regex 确定要公开的键。
--consul.server="http://localhost:8500" #Consul 服务器或代理的HTTP API 地址。 (以 https:// 为前缀以通过 HTTPS 连接)
--consul.ca-file="" #用于验证服务器证书真实性的 PEM 编码证书颁发机构的文件路径。
--consul.cert-file="" #PEM 编码证书的文件路径,与私钥一起使用以验证出口商的真实性。
--consul.key-file="" #PEM 编码私钥的文件路径,与证书一起使用以验证出口商的真实性。
--consul.server-name="" #当提供时,这将覆盖 TLS 证书的主机名。它可用于确保证书名称与我们声明的主机名匹配。
--consul.timeout=500ms #Consul API 的 HTTP 请求超时。
--consul.insecure #禁用 TLS 主机验证。
--consul.request-limit=0 #限制consul的最大并发请求数,0表示没有限制。
--consul.allow_stale #允许任何 Consul 服务器(非领导者)为读取服务。
--consul.require_consistent #强制读取完全一致。
--log.level=info #仅记录具有给定严重性或更高级别的消息。其中之一:[调试、信息、警告、错误]
--log.format=logfmt #日志信息的输出格式。其中之一:[logfmt, json]
4.3 准备consul_exporter.service文件
root@consul-01:~# cat /lib/systemd/system/consul_exporter.service
[Unit]
Description=consul_exporter
Documentation=https://prometheus.io
After=network.target
[Service]
type=simple
ExecStart=/usr/local/consul_exporter/consul_exporter
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always
[Install]
WantedBy=multi-user.target
4.4 设置开机启动
root@consul-01:~# systemctl enable consul_exporter
Created symlink /etc/systemd/system/multi-user.target.wants/consul_exporter.service → /lib/systemd/system/consul_exporter.service.
root@consul-01:~# systemctl start consul_exporter
root@consul-01:~# systemctl status consul_exporter
● consul_exporter.service - consul_exporter
Loaded: loaded (/lib/systemd/system/consul_exporter.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-11-25 19:57:00 CST; 3s ago
Docs: https://prometheus.io
Main PID: 23638 (consul_exporter)
Tasks: 4 (limit: 2245)
Memory: 1.5M
CGroup: /system.slice/consul_exporter.service
└─23638 /usr/local/consul_exporter/consul_exporter
Nov 25 19:57:00 consul-01 systemd[1]: Started consul_exporter.
Nov 25 19:57:00 consul-01 consul_exporter[23638]: level=info ts=2021-11-25T11:57:00.699Z caller=consul_exporter.go:486 msg="Starting consul_exporter" version="(version=0.7.1, branch=HEAD, revision=ae46e2ea980>
Nov 25 19:57:00 consul-01 consul_exporter[23638]: level=info ts=2021-11-25T11:57:00.699Z caller=consul_exporter.go:487 build_context="(go=go1.14.6, user=root@fdd571c00696, date=20200721-15:34:41)"
Nov 25 19:57:00 consul-01 consul_exporter[23638]: level=info ts=2021-11-25T11:57:00.700Z caller=consul_exporter.go:538 msg="Listening on address" address=:9107
4.5 验证consul exporter web界面

五 Prometheus添加consul exporter
5.1 修改Prometheus.yml文件
~# cat /usr/local/prometheus/prometheus.yml
- job_name: "consul-node"
static_configs:
- targets: ['192.168.174.103:9107']
5.2 重启Prometheus服务
~# systemctl restart prometheus.service
5.3 验证Prometheus web界面
