nginx的安裝與使用這里不再演示
添加nginx狀態的狀態模塊:
狀態模塊內容如下:
location /status { stub_status on; access_log off; allow 10.0.0.0/24; deny all; }
修改nginx
端口並重啟
測試:http://192.168.56.11:8080/status
[root@web01 ~]# curl http://10.0.0.9:8080/status/ Active connections: 1 server accepts handled requests 1 1 1 Reading: 0 Writing: 1 Waiting: 0
解釋說明:使用zabbix來監控活動連接數,通過status狀態模塊為前提
我們現在命令取出我們想要的值,例如:
[root@web01 ~]# curl http://10.0.0.9:8080/status/|grep Active|awk -F "[ ]" '{print $3}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 97 0 97 0 0 166k 0 --:--:-- --:--:-- --:--:-- 0
1
顯示監控的活動連接數為1
#提示: 如果想要加自定義監控項,不要在配置文件中寫入,可以在Include
里面定義的目錄寫上
只要我們寫在Include
目錄下,都可以識別到
[root@web01 ~]# cd /application/zabbix/etc/zabbix_agentd.conf.d/ [root@web01 zabbix_agentd.conf.d]# ll 總用量 8 -rw-r--r-- 1 1001 1001 121 9月 23 19:38 userparameter_mysql.conf -rw-r--r-- 1 root root 105 9月 24 17:23 userparameter_nginx.conf [root@web01 zabbix_agentd.conf.d]# vim userparameter_nginx.conf UserParameter=nginx.active,/usr/bin/curl -s http://10.0.0.9:8080/status|grep Active|awk -F "[ ]" '{print $3}'
說明:
參數:UserParameter,+定義的key: nginx.active +command
zabbix agentd會調用這個腳本
修改完之后重啟zabbix-agentd
zabbix服務端使用zabbix-get進行測試
[root@ZabbixServer yum.repos.d]# /application/zabbix/bin/zabbix_get -s 10.0.0.9 -k "nginx.active" 1
結果返回1,說明已經建立一個連接。
接下來,在zabbix-web上添加item
創建圖形:
效果:
測試觸發器
功能陳述:
當nginx連接數超出10個進行觸發報警顯示嚴重。
前面已經建立了nginx.active監控項了,現在創建觸發器
依賴關系可以不添加任何內容,這里只做測試,更新即可。
現在訪問測試:
[root@ZabbixServer ~]# ab -c 100 -n 10000 http://10.0.0.9:8080/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.0.0.9 (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: nginx/1.10.2 Server Hostname: 10.0.0.9 Server Port: 8080
報警頁面顯示效果:
如果想加入報警提示音的話,點擊用戶管理界面,將用戶提示音加進去即可。