首页 > 其他 > 详细

ZABBIX之NGINX监控

时间:2016-06-02 00:46:44      阅读:146      评论:0      收藏:0      [点我收藏+]
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监控

原文:http://www.cnblogs.com/tankt101/p/5551580.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!