zabbix监控nginx 开启status

1.修改客户端nginx皮配置文件

[root@khd ~]# vim /usr/local/nginx/conf/nginx.conf
......
#access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location /status {
            stub_status on;
            allow all;
        }
        #error_page  404              /404.html;

.....

2.修改客户端zabbix的配置文件

[root@khd ~]# vim /usr/local/etc/zabbix_agentd.conf
······
# Range: 0-1
# Default:
UnsafeUserParameters=1
UserParameter=nginx_status[*],/bin/bash /usr/local/etc/zabbix_agentd.conf.d/nginx_monitor.sh $1 //bash后面跟上脚本的绝对路径,$1代表参数


### Option: UserParameter
········
重启一下zabbix
[root@khd ~]# pkill zabbix
[root@khd ~]# zabbix_agentd 

3.写zabbix的监控脚本

[root@khd ~]# cd /usr/local/etc/zabbix_agentd.conf.d/
[root@khd zabbix_agentd.conf.d]# vim nginx_monitor.sh 

NGINX_PORT=80
NGINX_COMMAND=$1
nginx_active(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/status/" |awk '/Active/ {print $NF}'
}
nginx_reading(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/status/" |awk '/Reading/ {print $2}'
}
nginx_writing(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/status/" |awk '/Writing/ {print $4}'
       }
nginx_waiting(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/status/" |awk '/Waiting/ {print $6}'
       }
nginx_accepts(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/status/" |awk 'NR==3 {print $1}'
       }
nginx_handled(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/status/" |awk 'NR==3 {print $2}'
       }
nginx_requests(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/status/" |awk 'NR==3 {print $3}'
       }
  case $NGINX_COMMAND in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
      *)
echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
    esac
给脚本加执行权限
[root@khd zabbix_agentd.conf.d]# chmod +x nginx_monitor.sh 

4.在服务端测试键值能否使用

[root@fwd ~]# zabbix_get -s 192.168.153.173 -k nginx_status[waiting]

4.1 添加监控项和触发器


4.2验证

多开几个网页,触发监控

posted on 2019-06-10 21:58  LY是IT女  阅读(243)  评论(0编辑  收藏  举报

导航