1, Port auto Discovery Cat nginx_port.py
#!/usr/bin/Envpythonimport osimport Jsont=os.popen ("""Netstat-antp|awk '/listen/&&/nginx/{print $4} ' |awk-f: ' {print $NF} '""") Ports= [] forPortinchT.readlines (): R= Os.path.basename(Port.strip ()) Ports+= [{'{#NGINXPORT}': R}] Print Json.dumps ({'Data':p orts},sort_keys=true,indent=4, separators= (',',':'))
2, State script
Cat >>/usr/local/zabbix/bin/nginx_status <<end
#!/bin/BashfunctionActive {/usr/bin/curl"Http://localhost/stub-status" 2>/dev/NULL|grep 'Active'|awk '{print $NF}'}functionReading {/usr/bin/curl"Http://localhost/stub-status" 2>/dev/NULL|grep 'Reading'|awk '{print $}'}functionWriting {/usr/bin/curl"Http://localhost/stub-status" 2>/dev/NULL|grep 'Writing'|awk '{print $4}'}functionWaiting {/usr/bin/curl"Http://localhost/stub-status" 2>/dev/NULL|grep 'Waiting'|awk '{print $6}'}functionaccepts {/usr/bin/curl"Http://localhost/stub-status" 2>/dev/NULL|awknr==3|awk '{print $}'}functionhandled {/usr/bin/curl"Http://localhost/stub-status" 2>/dev/NULL|awknr==3|awk '{print $}'}functionRequests {/usr/bin/curl"Http://localhost/stub-status" 2>/dev/NULL|awknr==3|awk '{print $}'}# Run The requestedfunction $1
3, configuration file: Cat >>/usr/local/zabbix/conf/zabbix_agentd.conf <<end
# nginxuserparameter=nginx[*],/usr/local/zabbix/bin/nginx_status $1userparameter= nginx.discovery,/usr/local/zabbix/bin/nginx_port.py
4,
Killall Zabbix_agentd/usr/local/zabbix/sbin/zabbix_agentd
Zabbix's nginx monitoring