标签:zabbix监控nginx_status nginx监控
在网上看到了许多监控nginx状态的,发现大多都配置都比较复杂,我也写了一个自动发现的脚本,欢迎拍砖
nginx_status 具体的配置这里就不多说了,这里假装你已经配好了!
#coding=utf-8 import urllib,urllib2,urllib2 import sys,json url="http://112.124.32.164/nginx_status" li=["ActiveConnections","Reading","Writing","Waiting"] js=[] if len(sys.argv) < 2: for stat in li: js += [{‘{#NGINXSTATUS}‘:stat}] print json.dumps({‘data‘:js},sort_keys=True,indent=4,separators=(‘,‘,‘:‘)) else: arg=sys.argv[1] argm="%s:" % arg request = urllib2.Request(url) response = urllib2.urlopen(request) result=response.readlines() loop=0 dic={} for i in result: loop += 1 if loop == 1: ActiveConnections=int(i.split(":")[1]) dic[‘ActiveConnections:‘]=ActiveConnections elif loop == 4: Status=tuple(i.split(" ")) cloop=0 for st in Status: cloop += 1 if cloop == 2 : dic["Reading:"]=st elif cloop == 4: dic["Writing:"]=st elif cloop == 6: dic["Waiting:"]=st print dic[argm]
zabbix_agent 自定义键值配置
UserParameter=nginx.status[*], /usr/bin/python /etc/zabbix/nginx_statu.py $1
然后自动发现键值为
nginx.status
项目原型键值为
nginx.status[{#NGINXSTATUS}]
大神勿喷!
标签:zabbix监控nginx_status nginx监控
原文地址:http://sandy521.blog.51cto.com/5728588/1716852