Zabbix新增監控項nginx
阿新 • • 發佈:2018-11-19
環境配置:
實驗前刪除zabbix server主機需要刪除http監控模板,否則與nginx埠衝突
具體部署:
1、zabbix agent端配置nginx
[[email protected] ~]# rpm -ivh nginx-1.8.0-1.el6.ngx.x86_64.rpm
[[email protected] ~]# vim /etc/nginx/conf.d/default.conf
13 location /status {
14 stub_status on;
15 access_log off;
16 allow 127.0.0.1;
17 deny all;
18 }
[ [email protected] ~]# nginx -t
[[email protected] ~]# /etc/init.d/nginx start
2、新建zabbix監控模板
[[email protected] ~]# cd /etc/zabbix/zabbix_agentd.d/
[[email protected] zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf
[[email protected] zabbix_agentd.d]# vim userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | awk 'NR==1' | awk '{print $3}'
UserParameter=nginx.accept,curl -s http://127.0.0.1/status | awk 'NR==3' | awk '{print $1}'
UserParameter=nginx.request,curl -s http://127.0.0.1/status | awk 'NR==3' | awk '{print $3}'
[ [email protected] zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
3、zabbix agent端測試
- 訪問http://172.25.51.12/status
<1>當nginx的status允許所有主機訪問時,即:
[[email protected] ~]# vim /etc/nginx/conf.d/default.conf 13 location /status { 14 stub_status on; 15 access_log off; 16 }
<2>當nginx的status只允許內部迴環介面訪問時,即:
[[email protected] ~]# vim /etc/nginx/conf.d/default.conf
13 location /status {
14 stub_status on;
15 access_log off;
16 allow 127.0.0.1;
17 deny all;
18 }
- 內部迴環介面訪問nginx的status
4、zabbix server端測試
[[email protected] ~]# zabbix_get -s 172.25.51.12 -k nginx.active
[[email protected] ~]# zabbix_get -s 172.25.51.12 -k nginx.accept
[[email protected] ~]# zabbix_get -s 172.25.51.12 -k nginx.request
5、網頁配置
- 建立監控項(圖右上角)
注意鍵值,必須為agent端定義的:nginx.active/nginx.accept/nginx.request
- 建立圖形,圖形中新增監控項
圖形類別根據需求:正常、層積、pie
- 檢視監控結果