提供操作系统级别的监控指标,cpu
memory
disk space
diskio
network
-
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz
tar xf node_exporter-1.6.1.linux-amd64.tar.gz
cd node_exporter-*.linux-amd64/
./node_exporter --web.listen-address=":9100" \ --web.telemetry-path="/metrics" \ # 启动 systemd收集器 --collector.systemd \ --collector.systemd.unit-whitelist="(sshd|docker|rsyslog).service" \ # 禁止收集arp 指标 --no-collector.arp \ --log.format=json
-
配置Prometheus
由于node_export 返回大量指标,通过prometheus配置文件的collect 收集指定的指标
scrape_configs: - job_name: 'node' static_configs: - targets: ['10.4.7.11:9100','10.4.7.12:9100'] params: collect[]: - cpu - meminfo - netstat - systemd - xfs - filefd - filesystem
curl -g -X GET http://10.4.7.21:9100/metrics?collect[]=xfs curl -g -X GET 10.4.7.21:9100/metrics?collect[]=cpu
-
常用指标
机器宕机
up{job="node-exporter"} == 0
cpu使用率
cpu使用情况包括
system
,user
,idle
,iowait
cpu0 每秒使用率
irate(node_cpu_seconds_total{job="node",cpu="0"}[5m])
cpu0 平均使用率
avg(irate(node_cpu_seconds_total{job="node",cpu="0"}[5m]))by(mode)
cpu使用率
100-avg by(instance) (irate(node_cpu_seconds_total{job="node",mode="idle"}[5m]))*100
cpu 饱和度
通过1分钟 5分钟 15 分钟的负载展示。一般负载小于cpu 核心数1倍为正常
查询有几个逻辑核心
count(node_cpu_seconds_total{mode="idle"})by(instance)
node_load1 >on (instance) ( count by(instance) (node_cpu_seconds_total{mode="idle"})*1.5 ) node_load5 node_load15
memory
内存总量:
node_memory_MemTotal_bytes
buffer:
node_memory_Buffers_bytes
cache:
node_memory_Cached_bytes
free:
node_memory_MemFree_bytes
可用内存:
node_memory_MemAvailable_bytes
不可回收slab:
node_memory_SUnreclaim_bytes
内存使用率
1-(node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) >0.9
饱和度
通过检查内存和磁盘数据的交换来判断,
磁盘到到内存的 字节数/s:
node_vmstat_pswpin
内存到到磁盘的 字节数/s:
node_vmstat_pswpout
sum(rate(node_vmstat_pswpout[1m])+rate(node_vmstat_pswpin[1m]))by(instance)
磁盘
只能监控被挂在的,如果你有一块磁盘未被格式化和mount则无法通过该指标统计。
node_filesystem_size_bytes{mountpoint="/"} # 总大小 node_filesystem_free_bytes{mountpoint="/"} # 空闲大小 #使用比例 1-(node_filesystem_free_bytes{mountpoint="/"}/node_filesystem_size_bytes{mountpoint="/"}) >0.9
实际中我们使用predict_linear线性函数预测未来4个小时中磁盘的剩余空间
predict_linear(node_filesystem_free_bytes{mountpoint="/"}[1h],4*3600)<0
网络流量
# 入栈流量速率(M) irate(node_network_receive_bytes_total{device="eth0"}[30s])/1024/1024
# 出栈流量速率(M) irate(node_network_transmit_bytes_total{device="eth0"}[30s])/1024/1024
systemd服务指标
node_systemd_unit_state{name="docker.service"}
TCP连接
自定义指标
node_exporter 允许用户自定义监控指标,具体方法如下:
-
修改node_exportrer启动文件,添加如下选项
--collector.textfile \ --collector.textfile.directory="."
-
在
--collector.textfile.directory=
定义的目录下写入要提供的指标内容,文件以.prom
结尾vi httpcod.prom #输入示例: method_code:http_errors:rate5m{method="get", code="500"} 24 method_code:http_errors:rate5m{method="get", code="404"} 30 method_code:http_errors:rate5m{method="put", code="501"} 3 method_code:http_errors:rate5m{method="post", code="500"} 6 method_code:http_errors:rate5m{method="post", code="404"} 21 method:http_requests:rate5m{method="get"} 600 method:http_requests:rate5m{method="del"} 34 method:http_requests:rate5m{method="post"} 120
-
重启node_exporter
-
验证结果
-