Prometheus 自定義exporter 監控key

當Prometheus的node_exporter中沒有咱們須要的一些監控項時,就能夠如zabbix同樣定製一些key,讓其支持咱們所須要的監控項。node_exporter 可在啓動時指定路徑,並將該路徑下的 *.prom 識別爲監控數據文件。node

添加取值腳本

[root@one tmp]# cat /usr/local/node_exporter/key/key_runner 
#! /bin/bash

echo Logical_CPU_core_total  `cat /proc/cpuinfo| grep "processor"| wc -l`
echo logined_users_total     `who | wc -l`;
echo procs_total `ps aux|wc -l`
echo procs_zombie       `ps axo pid=,stat=|grep Z|wc -l`

執行效果bash

[root@one key]# bash  key_runner
Logical_CPU_core_total 2
logined_users_total 1
procs_total 148
procs_zombie 0

設置定時任務

* * * * * bash /usr/local/node_exporter/key/key_runner > /usr/local/node_exporter/key/key.prom

添加啓動參數

啓動node_exporter,指定新加key值的prom路徑curl

./node_exporter --collector.textfile.directory=/usr/local/node_exporter-0.16/key

驗證

查看metrics值是否新增了該監控項ui

[root@one key]# curl 127.0.0.1:9100/metrics|grep -E "Logical_CPU_core_total|logined_users_total|procs_total|procs_zombie"
# TYPE Logical_CPU_core_total untyped
Logical_CPU_core_total 2
# HELP logined_users_total Metric read from /usr/local/node_exporter/key/key.prom
# TYPE logined_users_total untyped
logined_users_total 1
# HELP procs_total Metric read from /usr/local/node_exporter/key/key.prom
# TYPE procs_total untyped
procs_total 151
# HELP procs_zombie Metric read from /usr/local/node_exporter/key/key.prom
# TYPE procs_zombie untyped
procs_zombie 0
相關文章
相關標籤/搜索