1. Open the status template in Nginx
[Email protected] ~]# vim/usr/local/nginx-1.8.0/conf/nginx.conf
Location/stat {
Stub_status on;
Access_log off;
Allow the IP address of the machine; #只允许本机访问
Deny all;
}
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/00/wKiom1cz9vjTnqJrAAAnL0sJH_k427.png "title=" 1.png " alt= "Wkiom1cz9vjtnqjraaanl0sjh_k427.png"/>
2. Write a script to monitor Nginx
[Email protected] ~]# vim/home/shell/nc_nginx_check.sh
#!/bin/bash
# Script to fetch nginx statuses for tribily monitoring systems
# Author:dick
# data:2016-05-12
host= the domain name of the website
# Functions to return nginx stats
Function Active {
/usr/bin/curl "/http $HOST/stat" 2>/dev/null| grep ' Active ' | awk ' {print $NF} '
}
function reading {
/usr/bin/curl "/http $HOST/stat" 2>/dev/null| grep ' Reading ' | awk ' {print $} '
}
function writing {
/usr/bin/curl "/http $HOST/stat" 2>/dev/null| grep ' Writing ' | awk ' {print $4} '
}
function waiting {
/usr/bin/curl "/http $HOST/stat" 2>/dev/null| grep ' Waiting ' | awk ' {print $6} '
}
function accepts {
/usr/bin/curl "/http $HOST/stat" 2>/dev/null| awk nr==3 | awk ' {print '} '
}
function handled {
/usr/bin/curl "/http $HOST/stat" 2>/dev/null| awk nr==3 | awk ' {print $} '
}
function requests {
/usr/bin/curl "/http $HOST/stat" 2>/dev/null| awk nr==3 | awk ' {print $} '
}
# Run The requested function
$ #接收第一个参数
[Email protected] ~]# vim/etc/zabbix/zabbix_agentd.conf #添加如下参数
Unsafeuserparameters=1
Userparameter=nginx.accepts,/home/shell/nc_nginx_check.sh accepts
Userparameter=nginx.handled,/home/shell/nc_nginx_check.sh handled
userparameter=nginx.requests,/home/shell/nc_nginx_check.sh Requests
Userparameter=nginx.connections.active,/home/shell/nc_nginx_check.sh Active
userparameter=nginx.connections.reading,/home/shell/nc_nginx_check.sh Reading
userparameter=nginx.connections.writing,/home/shell/nc_nginx_check.sh Writing
Userparameter=nginx.connections.waiting,/home/shell/nc_nginx_check.sh Waiting
[Email protected] ~]#/etc/init.d/zabbix-agent restart
Shutting down Zabbix agent: [OK]
Starting Zabbix agent: [OK]
[Email protected] ~]#
3. Test if there is data on the Zabbix server
[email protected] ~]# Yum install zabbix-get-y
[[email protected] ~]# zabbix_get-s The IP address of the monitored end-K "Nginx.accepts"
16187540
[[email protected] ~]# zabbix_get-s The IP address of the monitored end-K "nginx.handled"
16187585
[[email protected] ~]# zabbix_get-s The IP address of the monitored end-K "Nginx.requests"
55652248
[[email protected] ~]# zabbix_get-s The IP address of the monitored end-K "Nginx.connections.active"
349
[Email protected] ~]#
4. Add templates, categories, items in the Zabbix window
(1). Create a template
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/00/wKiom1cz-6fRHMWEAAB-d8EmsaE174.png "style=" float: none; "title=" 2.png "alt=" Wkiom1cz-6frhmweaab-d8emsae174.png "/>
(2). Create a Category
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/00/wKiom1cz-6ihLq0ZAABKtWmmSZA353.png "style=" float: none; "title=" 3.png "alt=" Wkiom1cz-6ihlq0zaabktwmmsza353.png "/>
(3). Create an app set
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/80/00/wKiom1cz-6iBxpa3AAA5xk_xj6A897.png "style=" float: none; "title=" 4.png "alt=" Wkiom1cz-6ibxpa3aaa5xk_xj6a897.png "/>
(4). Create a project
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7F/FE/wKioL1cz_InR9meHAABIFVaf9uM307.png "style=" float: none; "title=" 5.png "alt=" Wkiol1cz_inr9mehaabifvaf9um307.png "/>
(5). Create a monitoring entry
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7F/FE/wKioL1cz_InhPLXJAAAo8_97nSA366.png "style=" float: none; "title=" 7.png "alt=" Wkiol1cz_inhplxjaaao8_97nsa366.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/80/00/wKiom1cz-6nBQO90AABDSJzrMm8978.png "style=" float: none; "title=" 8.png "alt=" Wkiom1cz-6nbqo90aabdsjzrmm8978.png "/>
5. View the status chart for monitoring
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/FE/wKioL1cz_enz7HUpAAB3DBdMlrc654.png "title=" 30.png "alt=" Wkiol1cz_enz7hupaab3dbdmlrc654.png "/>
Error Summary:
[[email protected] ~]# zabbix_get-s The IP address of the monitored end-K "Nginx.connections.writing"
Zbx_notsupported:timeout while executing a shell script.
Workaround:
To modify the timeout parameter on the zabbix_agent side
[Email protected] ~]# vim/etc/zabbix/zabbix_agentd.conf
Timeout=20 #默认是关闭, remove the comment and change the value to 20
This article is from the "Days Together" blog, please be sure to keep this source http://tongcheng.blog.51cto.com/6214144/1772583
Zabbix monitoring Nginx