zabbix监控nginx服务器连接数

nginx.conf 相关配置 ,开启status

location /status {
       stub_status on;
       access_log off;
          allow 127.0.0.1;
       deny all;
  }

相关脚本如下

[root@localhost zabbix_agentd.d]# cat nginx_status.sh 
#!/bin/bash
#this script is used to get nginx connetion status
#nginx status
 
HOST="127.0.0.1"
PORT="8080"
 
 
metric=$1
tmp_file=/tmp/nginx_status.txt
 /usr/bin/curl -s http://$HOST:$PORT/status > $tmp_file
 
case $metric in
 pid)
 output=`/sbin/pidof nginx | wc -l`
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 active)
 output=$(awk 'NR==1{print $3}' $tmp_file)
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 accepts)
 output=$(awk 'NR==3{print $1}' $tmp_file)
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 handled)
 output=$(awk 'NR==3{print $2}' $tmp_file)
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 requests)
 output=$(awk 'NR==3{print $3}' $tmp_file)
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 reading)
 output=$(awk 'NR==4{print $2}' $tmp_file)
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 writing)
 output=$(awk 'NR==4{print $4}' $tmp_file)
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 waiting)
 output=$(awk 'NR==4{print $6}' $tmp_file)
 if [ "$output" == "" ];then
 echo 0
 else
 echo $output
 fi
 ;;
 *)
 echo -e "\e[033mUsage: sh $0 [pid|active|accepts|handled|requests|reading|writing|waiting]\e[0m"

agent相关配置

[root@localhost zabbix_agentd.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@localhost zabbix_agentd.d]# cat nginx_status.conf 
UserParameter=nginx.status[*],/usr/bin/sh /etc/zabbix/zabbix_agentd.d/nginx_status.sh $1

重启agent

相关模板下载 zbx_tcp_templates.xml


zabbix监控nginx服务器连接数
http://www.jcwit.com/article/226/
作者
Carlos
发布于
2019年6月3日
许可协议