提供操作系統級別的監控指標,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
-
驗證結果
-