部署zabbix
详情请点击这里zabbix部署
首先部署zbbix
环境
主机名 | IP |
---|---|
R1服务端 | 192.168.77.33 |
R2客户端 | 192.168.100.77 |
在客户端和上部署nginx
详情请点击nginx
配置nginx
[root@R2 ~]# vim /usr/local/nginx/conf/nginx.conf location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; allow 192.168.100.123; deny all; } [root@R2 ~]# nginx -s reload
[root@R2 ~]# mkdir /scripts [root@R2 ~]# vim /scripts/check_nginx.sh #!/bin/bash #Script to fetch nginx statuses for monitoring systems HOST="127.0.0.1" PORT="80" function ping { /sbin/pidof nginx | wc -l } function active { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}' } function reading { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}' } function writing { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}' } function waiting { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}' } function accepts { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}' } function handled { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}' } function requests { /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}' } $1 [root@R2 ~]# chmod +x /scripts/check_nginx.sh
zabbix_agent配置文件开启自定义功能
[root@R2 ~]# vim /usr/local/etc/zabbix_agentd.conf UnsafeUserParameters=1 //取消注释并改为1 UserParameter=check_nginx[*],/bin/bash /scripts/check_nginx.sh $1 //在配置文件最后加 [root@R2 ~]# pkill zabbix [root@R2 ~]# zabbix_agentd
测试server端时候可以收到数据
[root@R1 etc]# zabbix_get -s 192.168.100.123 -p 10050 -k check_nginx[accepts] 9 [root@R1 etc]# zabbix_get -s 192.168.100.123 -k heck_nginx[active] 1
在Web界面配置
这样就可以实时监控数据
数据的表现就会在图中显示