有些时候,监控的服务输出Perfdata为空,nagiosgraph就没法绘图了。比如自己定义的监控服务。这个时候就需要对output数据进行处理,以便于生成rrd文件。
这就需要对map文件进行修改,其实map文件就是个perl脚本,定义一些正则表达式来对监控结果输出的处理。文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/
输出包含两个不同的输出。第一部分是“Status Information”,对应于map文件的output。“|”后面的数据是“Performance Data”对应于map文件的perfdata。这个可以在在Nagios的Web界面的服务细节中找到。文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/
例如下面的监控输出:
OK - Memory Usage: 2.53GB mapped, 5.06GB mappedWithJournal
OK - Memory Usage: 0.29GB resident, 5.38GB virtual, 2.53GB mapped, 5.06GB mappedWithJournal文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/
将下面的正则表达式添加到map文件中:文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/
# vim /usr/local/nagiosgraph/etc/map (/output:.*Memory Usage: ([-.0-9]+)GB\smapped.*?([-.0-9]+)GB\smappedWithJournal/ and push @s, [ 'memory', ['mapped', GAUGE, $1], ['smappedWithJournal', GAUGE, $2]]) or (/output:.*Memory Usage: ([-.0-9]+)GB\sresident,\s([-.0-9]+)GB\svirtual,\s([-.0-9]+)GB\smapped,\s([-.0-9]+)GB\smappedWithJournal/ and push @s, [ 'memory', ['resident', GAUGE, $1], ['virtual', GAUGE, $2], ['mapped', GAUGE, $3], ['mappedWithJournal', GAUGE, $4]]);
检测map语法是否正确:文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/
# perl -c map map syntax OK
这样就nagiosgraph可以正常的绘图了。文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/
这里就不贴出图来了,这个是nagios监控mongodb插件的输出,插件自带有生成perfdata的结果。文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/ 文章源自运维生存时间-https://www.ttlsa.com/nagios/custom-nagiosgraph-map-matching-rules-one-case/
评论