码迷,mamicode.com
首页 > 其他好文 > 详细

ZABBIX之NGINX监控

时间:2016-06-02 00:48:34      阅读:234      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!