Prometheus 自定义exporter 监控key

当Prometheus的node_exporter中没有我们需要的一些监控项时,就可以如zabbix一样定制一些key,让其支持我们所需要的监控项。node_exporter 可在启动时指定路径,并将该路径下的 *.prom 识别为监控数据文件。

添加取值脚本

[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`

执行效果

[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路径

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

验证

查看metrics值是否新增了该监控项

[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
posted @ 2019-02-21 15:05  huandada  阅读(...)  评论(...编辑  收藏