Zabbix5.0 使用原模板监控nginx状态

版本:zabbix5.0

操作系统:centos7.9

nginx版本:1.20

配置如下:

zabbix模板配置:

Zabbix5.0 使用原模板监控nginx状态

 

zabbix客户端配置:

[root@localhost zabbix_agentd.d]#more nginx_monitor.conf
UserParameter=nginx_status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/nginx_monitor.sh "$1"

 

[root@localhost zabbix_agentd.d]#more nginx_monitor.sh
#!/bin/bash
#注意Nginx监控的端口
NGINX_PORT=80
NGINX_COMMAND=$1
nginx_active(){
    /usr/bin/curl -s http://127.0.0.1:$NGINX_PORT/nginx_status |awk ‘/Active/ {print $NF}‘
}
nginx_reading(){
    /usr/bin/curl -s http://127.0.0.1:$NGINX_PORT/nginx_status |awk ‘/Reading/ {print $2}‘
}
nginx_writing(){
    /usr/bin/curl -s http://127.0.0.1:$NGINX_PORT/nginx_status |awk ‘/Writing/ {print $4}‘
       }
nginx_waiting(){
    /usr/bin/curl -s http://127.0.0.1:$NGINX_PORT/nginx_status |awk ‘/Waiting/ {print $6}‘
       }
nginx_accepts(){
    /usr/bin/curl -s http://127.0.0.1:$NGINX_PORT/nginx_status |awk ‘NR==3 {print $1}‘
       }
nginx_handled(){
    /usr/bin/curl -s http://127.0.0.1:$NGINX_PORT/nginx_status |awk ‘NR==3 {print $2}‘
       }
nginx_requests(){
    /usr/bin/curl -s http://127.0.0.1:$NGINX_PORT/nginx_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

 

 

然后重起服务:systemctl restart zabbix-agent

 nginx配置:

 1 server {
 2         listen       80;
 3         server_name  localhost;
 4 
 5         #charset koi8-r;
 6 
 7         #access_log  logs/host.access.log  main;
 8 
 9         location / {
10         proxy_pass http://auth;
11 
12         proxy_set_header Host $host:$server_port;
13         }
14         location /nginx_status {
15                 stub_status on;
16                 access_log off;
17                 allow 127.0.0.1;
18                 deny all;
19         }

 

Zabbix5.0 使用原模板监控nginx状态

上一篇:页面滚动时导航渐变


下一篇:终端配置的一些小问题