ZABBIX之NGINX监控
Posted Tank
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZABBIX之NGINX监控相关的知识,希望对你有一定的参考价值。
1,端口自动发现
cat nginx_port.py
#!/usr/bin/env python import os import json t=os.popen("""netstat -antp|awk ‘/LISTEN/&&/nginx/{print $4}‘|awk -F: ‘{print $NF}‘ """) ports = [] for port in t.readlines(): r = os.path.basename(port.strip()) ports += [{‘{#NGINXPORT}‘:r}] print json.dumps({‘data‘:ports},sort_keys=True,indent=4,separators=(‘,‘,‘:‘))
2, 状态脚本
cat >>/usr/local/zabbix/bin/nginx_status <<end
#!/bin/bash function active { /usr/bin/curl "http://localhost/stub-status" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘ } function reading { /usr/bin/curl "http://localhost/stub-status" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘ } function writing { /usr/bin/curl "http://localhost/stub-status" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘ } function waiting { /usr/bin/curl "http://localhost/stub-status" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘ } function accepts { /usr/bin/curl "http://localhost/stub-status" 2>/dev/null| awk NR==3 | awk ‘{print $1}‘ } function handled { /usr/bin/curl "http://localhost/stub-status" 2>/dev/null| awk NR==3 | awk ‘{print $2}‘ } function requests { /usr/bin/curl "http://localhost/stub-status" 2>/dev/null| awk NR==3 | awk ‘{print $3}‘ } # Run the requested function $1
3, 配置文件:
cat >>/usr/local/zabbix/conf/zabbix_agentd.conf <<end
# nginx UserParameter=nginx[*],/usr/local/zabbix/bin/nginx_status $1 UserParameter=nginx.discovery,/usr/local/zabbix/bin/nginx_port.py
4,
killall zabbix_agentd
/usr/local/zabbix/sbin/zabbix_agentd
以上是关于ZABBIX之NGINX监控的主要内容,如果未能解决你的问题,请参考以下文章
Zabbix:项目实战之--自动发现nginx调度器及后端web服务集群自定义参数监控