Zabbix nginx
回帖(1)
2020-11-4 16:16:16
1、导入模版
配置-模版-导入
选择文件-导入
配置-模版-名称:nginx -应用
2、创建zabbix-agent自定义配置文件,把脚本放在指定目录
[root@agentd2 zabbix_agentd.d]# cat user_def.conf UserParameter=nginx.status
- ,/bin/bash /etc/zabbix/scripts/nginx_status.sh $1 #黄色是keyUserParameter=staut, netstat -ant |grep ESTABLISHED |wc -lUserParameter=ESTABLISHED,netstat -ant |grep -c ESTABLISHEDUserParameter=SYN_SENT,netstat -ant |grep -c SYN_SENTUserParameter=SYN_RECV,netstat -ant |grep -c SYN_RECVUserParameter=FIN_WAIT1,netstat -ant |grep -c FIN_WAIT1UserParameter=FIN_WAIT2,netstat -ant |grep -c FIN_WAIT2UserParameter=TIME_WAIT,netstat -ant |grep -c TIME_WAITUserParameter=CLOSE,netstat -ant |grep -c CLOSEUserParameter=CLOSE_WAIT,netstat -ant |grep -c CLOSE_WAITUserParameter=LAST_ACK,netstat -ant |grep -c LAST_ACKUserParameter=LISTEN,netstat -ant |grep -c LISTENUserParameter=CLOSING,netstat -ant |grep -c CLOSING
确定/etc/zabbix/scripts/nginx_status.sh 脚本存在 并执行无报错
#!/bin/bashHOST="127.0.0.1"PORT="80" function ping { /***in/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}'}# 执行function$1
View Code
3、zabbix_get测试取值
[root@localhost zabbix]# zabbix_get -s 192.168.123.26 -k nginx.status[accepts]172[root@localhost zabbix]# zabbix_get -s 192.168.123.26 -k nginx.status[reading]0[root@localhost zabbix]# zabbix_get -s 192.168.123.26 -k nginx.status[ping] 1随机测试参数,测试没问题,可以创建主机,或者关联模版等操作
4创建主机(已存在直接)关联模版
1、导入模版
配置-模版-导入
选择文件-导入
配置-模版-名称:nginx -应用
2、创建zabbix-agent自定义配置文件,把脚本放在指定目录
[root@agentd2 zabbix_agentd.d]# cat user_def.conf UserParameter=nginx.status
- ,/bin/bash /etc/zabbix/scripts/nginx_status.sh $1 #黄色是keyUserParameter=staut, netstat -ant |grep ESTABLISHED |wc -lUserParameter=ESTABLISHED,netstat -ant |grep -c ESTABLISHEDUserParameter=SYN_SENT,netstat -ant |grep -c SYN_SENTUserParameter=SYN_RECV,netstat -ant |grep -c SYN_RECVUserParameter=FIN_WAIT1,netstat -ant |grep -c FIN_WAIT1UserParameter=FIN_WAIT2,netstat -ant |grep -c FIN_WAIT2UserParameter=TIME_WAIT,netstat -ant |grep -c TIME_WAITUserParameter=CLOSE,netstat -ant |grep -c CLOSEUserParameter=CLOSE_WAIT,netstat -ant |grep -c CLOSE_WAITUserParameter=LAST_ACK,netstat -ant |grep -c LAST_ACKUserParameter=LISTEN,netstat -ant |grep -c LISTENUserParameter=CLOSING,netstat -ant |grep -c CLOSING
确定/etc/zabbix/scripts/nginx_status.sh 脚本存在 并执行无报错
#!/bin/bashHOST="127.0.0.1"PORT="80" function ping { /***in/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}'}# 执行function$1
View Code
3、zabbix_get测试取值
[root@localhost zabbix]# zabbix_get -s 192.168.123.26 -k nginx.status[accepts]172[root@localhost zabbix]# zabbix_get -s 192.168.123.26 -k nginx.status[reading]0[root@localhost zabbix]# zabbix_get -s 192.168.123.26 -k nginx.status[ping] 1随机测试参数,测试没问题,可以创建主机,或者关联模版等操作
4创建主机(已存在直接)关联模版
举报
更多回帖