Zabbix monitoring Nginx needs to open nginx status, to confirm the Nginx compiled Http_sub_module module.
1, check whether the current Nginx installation configuration Http_sub_module module
# nginx-v
tengine version:tengine/1.5.2 (nginx/1.2.9)
built by GCC 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
TL S SNI Support enabled
Configure arguments:--prefix=/data/prg/nginx--with-pcre=. /pcre-8.32/--with-http_stub_status_module--without-select_module--without-poll_module--with-http_concat_module --with-http_sysguard_module--add-module=. /ngx_cache_purge-2.0--with-http_perl_module
If you can see the--with-http_sub_module module in your environment, it means that status can be enabled. If not, you can add them at compile time.
2. Configure Nginx Status
server {
listen 8080;
Access_log off;
server_name localhost;
root/var/www/html;
Location/nginxstatus {
stub_status on;
Access_log off;
Allow 127.0.0.1;
Deny all;
}
}
Reload Nginx–s After configuration is complete reload
3. Visit http://127.0.0.1:8080/NginxStatus/to see status information
4. Write nginx_status.sh script (/data/prg/zabbix/scripts/nginx_status.sh)
#!/bin/bash # datetime:2017-01-22 # author:kbsonlong # Description:zabbix Monitor nginx performance and process status # Note: This script needs to be configured on the monitored side # zabbix_ag Entd.conf: Add custom key,userparameter=nginx.status[*],/data/prg/zabbix/scripts/nginx_status.sh-f $1-p $ HOST= " 127.0.0.1 "port=" 80 "# detects if Nginx process exists function ping {/sbin/pidof nginx | wc-l} # detect Nginx Performance function active {/ Usr/bin/curl "/http $HOST: $PORT/nginxstatus/" 2>/dev/null| grep ' Active ' | awk ' {print $NF} ' function reading {/usr/bin/curl '/'/' $HOST: $PORT/nginxstatus/' 2>/dev/null| grep ' reading ' | awk ' {print $} '} function writing {/usr/bin/curl "http://$HOST $PORT/nginxstatus/" 2>/dev/null| grep ' writing ' | awk ' {print $4} '} function waiting {/usr/bin/curl '/'/$HOST: $PORT/nginxstatus/' 2>/dev/null| grep ' waiting ' | awk ' {print $6} '} function accepts {/usr/bin/curl '/'/$HOST: $PORT/nginxstatus/' 2>/dev/null| awk nr==3 | awk ' {print '} ' function handled {/usr/bin/curl '/' $HOST: $PORT/nginxstatus/"2>/dev/null| awk nr==3 | awk ' {print $} '} function requests {/usr/bin/curl ' http:/$HOST $PORT/nginxstatus/"2>/dev/null| awk nr==3 | awk ' {print $} '} # performs function while getopts "h:p:f:" OPT;
Do case $OPT in "P") port= $OPTARG;;
"F") fun= $OPTARG;;
"H") host= $OPTARG;; Esac done $fun
5, Zabbix Agent configuration of the custom key
Vim/data/prg/zabbix/etc/zabbix_agentd.conf
Unsafeuserparameters=1
Userparameter=nginx.status[*],/data/prg/zabbix/scripts/nginx_status.sh-f $1-p
The Zabbix agent needs to be restarted after the configuration is complete, and the custom key will take effect.
6, Zabbix web-side configuration monitoring template, save the following content XML file, and then import the template, you can find the Nginx.status template (note that this template monitoring port is 8080, if you need to modify the monitoring port, you can directly replace the XML file 8080 port, or modified in the Web interface after import)
<?xml version= "1.0" encoding= "UTF-8"?> <zabbix_export> <version>3.2</version> <date>
2017-01-22t08:57:20z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>ngin X.status</template> <name>nginx.status</name> <description/> & lt;groups> <group> <name>Templates</name> </gr
oup> </groups> <applications> <application>
<name>nginx.status</name> </application> </applications>
<items> <item> <name>nginx accepts</name> <type>0</type> <snmp_community/> <multiplier>0</multiplier> <snmp_oid/> <key>nginx.status[accepts,8080]</key> <dela Y>30</delay>