使用Zabbix监控Nginx状态页实战案例

摘要:
否则,将追究法律责任。Accepts:Nginx自启动以来已接受的客户端请求总数。对于操作和维护,没有太多的参考,因为如果我们长时间不重新启动nginx服务,数量可能会很大。这意味着与nginx的连接正在建立,但尚未成功建立。如果这个数字很大,则意味着您的nginx服务器相对较慢,需要排队才能与用户建立连接,因此需要考虑优化。写入:当前状态,向客户端发送响应消息过程中的连接数。

           使用Zabbix监控Nginx状态页实战案例

                                     作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。 

一.编译安装nginx步骤详解并开启状态页

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie/p/12031651.html
    https://www.cnblogs.com/yinzhengjie/p/12045736.html
使用Zabbix监控Nginx状态页实战案例第1张使用Zabbix监控Nginx状态页实战案例第2张
[root@nginx201.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /yinzhengjie/softwares/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /nginx_status {
            stub_status;
        }
    }
}
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /yinzhengjie/softwares/nginx/conf/nginx.conf

使用Zabbix监控Nginx状态页实战案例第3张

  状态页用于输出nginx的基本状态信息,下面是关于输出信息的详细说明:
    Active connections: 
      当前处于活动状态的客户端连接数,包括连接等待空闲连接数。当这个数值非常大时,我们得考虑nginx后端提供的web服务以及数据库性能上是否可以hold住。
    accepts:
      统计总值,Nginx自启动后已经接受的客户端请求的总数。对于运维来说,并没有太大的参考一样,因为如果我们长期不重启nginx服务,那么这个数字可能会很大。
    handled:
      统计总值,Nginx自启动后已经处理完成的客户端请求的总数,通常等于accepts,除非有因worker_connections限制等被拒绝的连接。同理,这个参数的参考意义对运维人员来说也不大。
    requests:
      统计总值,Nginx自启动后客户端发来的总的请求数。这个数值会很大,因为一个链接会有多个请求。
    Reading:
      当前状态,正在读取客户端请求报文首部的连接的连接数。即表示正在和nginx建立连接但还没有建立成功,如果这个数字很大的话,说明你的nginx服务器处理速度相对比较慢,和用户建立连接都需要排队了,所以得考虑做优化。
    Writing:
      当前状态,正在向客户端发送响应报文过程中的连接数。如果这个数字过大,可能是响应报文给客户端可能会涉及到静态资源(比如js,css,html)获取速度较慢(因为有资源是在本地服务器,有的是在后端服务器,有的资源可能没有及时响应)会导致整个响应过程很慢。
    Waiting:
      当前状态,正在等待客户端发出请求的空闲连接数,开启 keep-alive的情况下,这个值等于active – (reading+writing),

二.在Nginx服务器上部署Zabbix Agent

1>.下载zabbix源码包

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie2020/p/12305427.html

2>.安装依赖包

[root@nginx201.yinzhengjie.org.cn ~]# tar zxf zabbix-4.0.17.tar.gz

3>.配置安装参数

[root@nginx201.yinzhengjie.org.cn ~]# cd zabbix-4.0.17/
[root@nginx201.yinzhengjie.org.cn ~/zabbix-4.0.17]# 
[root@nginx201.yinzhengjie.org.cn ~/zabbix-4.0.17]# ./configure --prefix=/yinzhengjie/softwares/zabbix --enable-agent 

4>.编译并安装zabbix agent

使用Zabbix监控Nginx状态页实战案例第4张使用Zabbix监控Nginx状态页实战案例第5张
[root@nginx201.yinzhengjie.org.cn ~]# lscpu 
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 158
Model name:            Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Stepping:              10
CPU MHz:               2207.997
BogoMIPS:              4415.99
Virtualization:        VT-x
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              9216K
NUMA node0 CPU(s):     0,1
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid s
se4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt arat spec_ctrl intel_stibp flush_l1d 
arch_capabilities
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# lscpu | grep "^CPU(s)"
CPU(s):                2
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# lscpu | grep "^CPU(s)"
[root@nginx201.yinzhengjie.org.cn ~/zabbix-4.0.17]# make -j 2 && make install

5>.修改agent端的配置文件

[root@nginx201.yinzhengjie.org.cn ~]# cp /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf-`date +%F`
使用Zabbix监控Nginx状态页实战案例第6张使用Zabbix监控Nginx状态页实战案例第7张
[root@nginx201.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total 0
drwxr-xr-x 2 root root 45 Feb 21 19:28 bin
drwxr-xr-x 3 root root 60 Feb 21 19:32 etc
drwxr-xr-x 3 root root 21 Feb 21 19:28 lib
drwxr-xr-x 2 root root 27 Feb 21 19:28 sbin
drwxr-xr-x 3 root root 17 Feb 21 19:28 share
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# mkdir -v /yinzhengjie/softwares/zabbix/pid
mkdir: created directory ‘/yinzhengjie/softwares/zabbix/pid’
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total 0
drwxr-xr-x 2 root root 45 Feb 21 19:28 bin
drwxr-xr-x 3 root root 60 Feb 21 19:32 etc
drwxr-xr-x 3 root root 21 Feb 21 19:28 lib
drwxr-xr-x 2 root root  6 Feb 21 19:33 pid
drwxr-xr-x 2 root root 27 Feb 21 19:28 sbin
drwxr-xr-x 3 root root 17 Feb 21 19:28 share
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# mkdir -v /yinzhengjie/softwares/zabbix/pid
使用Zabbix监控Nginx状态页实战案例第8张使用Zabbix监控Nginx状态页实战案例第9张
[root@nginx201.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total 0
drwxr-xr-x 2 root root 45 Feb 21 19:28 bin
drwxr-xr-x 3 root root 60 Feb 21 19:32 etc
drwxr-xr-x 3 root root 21 Feb 21 19:28 lib
drwxr-xr-x 2 root root  6 Feb 21 19:33 pid
drwxr-xr-x 2 root root 27 Feb 21 19:28 sbin
drwxr-xr-x 3 root root 17 Feb 21 19:28 share
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# mkdir -v /yinzhengjie/softwares/zabbix/logs
mkdir: created directory ‘/yinzhengjie/softwares/zabbix/logs’
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/
total 0
drwxr-xr-x 2 root root 45 Feb 21 19:28 bin
drwxr-xr-x 3 root root 60 Feb 21 19:32 etc
drwxr-xr-x 3 root root 21 Feb 21 19:28 lib
drwxr-xr-x 2 root root  6 Feb 21 19:34 logs
drwxr-xr-x 2 root root  6 Feb 21 19:33 pid
drwxr-xr-x 2 root root 27 Feb 21 19:28 sbin
drwxr-xr-x 3 root root 17 Feb 21 19:28 share
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# mkdir -v /yinzhengjie/softwares/zabbix/logs mkdir: created directory ‘/yinzhengjie/softwares/zabbix/logs’
使用Zabbix监控Nginx状态页实战案例第10张使用Zabbix监控Nginx状态页实战案例第11张
[root@nginx201.yinzhengjie.org.cn ~]# grep ^LogFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's#(LogFile=)/tmp#1/yinzhengjie/softwares/zabbix/logs#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# grep ^LogFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
LogFile=/yinzhengjie/softwares/zabbix/logs/zabbix_agentd.log
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's#(LogFile=)/tmp#1/yinzhengjie/softwares/zabbix/logs#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
使用Zabbix监控Nginx状态页实战案例第12张使用Zabbix监控Nginx状态页实战案例第13张
[root@nginx201.yinzhengjie.org.cn ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
# PidFile=/tmp/zabbix_agentd.pid
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's@# (PidFile=)/tmp@1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# grep PidFile= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
PidFile=/yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's@# (PidFile=)/tmp@1/yinzhengjie/softwares/zabbix/pid@' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
使用Zabbix监控Nginx状态页实战案例第14张使用Zabbix监控Nginx状态页实战案例第15张
[root@nginx201.yinzhengjie.org.cn ~]# grep ^Server= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
Server=127.0.0.1
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's#(Server=)127.0.0.1#1172.200.5.203#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# grep ^Server= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
Server=172.200.5.203
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's#(Server=)127.0.0.1#1172.200.5.203#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
使用Zabbix监控Nginx状态页实战案例第16张使用Zabbix监控Nginx状态页实战案例第17张
[root@nginx201.yinzhengjie.org.cn ~]# grep ^Hostname= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
Hostname=Zabbix server
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's#(Hostname=)Zabbix server#1nginx201.yinzhengjie.org.cn#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# grep ^Hostname= /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
Hostname=nginx201.yinzhengjie.org.cn
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i 's#(Hostname=)Zabbix server#1nginx201.yinzhengjie.org.cn#' /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf

6>.并创建zabbix用户 

[root@nginx201.yinzhengjie.org.cn ~]# groupadd zabbix
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# useradd zabbix -s /sbin/nologin -M -g zabbix
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# chown zabbix:zabbix /yinzhengjie/softwares/zabbix/ -R
[root@nginx201.yinzhengjie.org.cn ~]# 

使用Zabbix监控Nginx状态页实战案例第18张

7>.编写zabbix agent端的启动脚本并配置其开机自启动

使用Zabbix监控Nginx状态页实战案例第19张使用Zabbix监控Nginx状态页实战案例第20张
[root@nginx201.yinzhengjie.org.cn ~]# vim /lib/systemd/system/zabbix-agent.service
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# cat /lib/systemd/system/zabbix-agent.service
[Unit]
Description=Yinzhengjie's Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/default/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid
KillMode=control-group
ExecStart=/yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# vim /lib/systemd/system/zabbix-agent.service
[root@nginx201.yinzhengjie.org.cn ~]# systemctl daemon-reload 
[root@nginx201.yinzhengjie.org.cn ~]#
[root@nginx201.yinzhengjie.org.cn ~]# systemctl start zabbix-agent.service 
[root@nginx201.yinzhengjie.org.cn ~]#
[root@nginx201.yinzhengjie.org.cn ~]# systemctl enable zabbix-agent.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# systemctl list-unit-files | grep zabbix-agent.service
zabbix-agent.service                          enabled 
[root@nginx201.yinzhengjie.org.cn ~]# 
使用Zabbix监控Nginx状态页实战案例第21张使用Zabbix监控Nginx状态页实战案例第22张
[root@nginx201.yinzhengjie.org.cn ~]# systemctl status zabbix-agent.service 
● zabbix-agent.service - Yinzhengjie's Zabbix Agent
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-02-21 19:44:42 CST; 2min 41s ago
 Main PID: 20201 (zabbix_agentd)
   CGroup: /system.slice/zabbix-agent.service
           ├─20201 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
           ├─20202 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
           ├─20203 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
           ├─20204 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
           ├─20205 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
           └─20206 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

Feb 21 19:44:42 nginx201.yinzhengjie.org.cn systemd[1]: Starting Yinzhengjie's Zabbix Agent...
Feb 21 19:44:42 nginx201.yinzhengjie.org.cn systemd[1]: Can't open PID file /yinzhengjie/softwares/zabbix/pid/zabbix_agentd.pid (yet?) after start: No such file or directory
Feb 21 19:44:42 nginx201.yinzhengjie.org.cn systemd[1]: Started Yinzhengjie's Zabbix Agent.
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# systemctl status zabbix-agent.service

使用Zabbix监控Nginx状态页实战案例第23张

三.监控Nginx实战案例

1>.编写nginx的自定义监控脚本

使用Zabbix监控Nginx状态页实战案例第24张使用Zabbix监控Nginx状态页实战案例第25张
[root@nginx201.yinzhengjie.org.cn ~]# vim /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh 
#!/bin/bash
#
host=${2:-'127.0.0.1'}
port=${3:-'80'}
page=${4:-'nginx_status'}
info=$(/usr/bin/curl --connect-timeout 5 -s http://${host}:${port}/${page} 2>/dev/null)
code=$(/usr/bin/curl --connect-timeout 5 -o /dev/null -s -w %{http_code} http://${host}:${port}/${page})
proc=$(/usr/bin/pgrep nginx | wc -l)

case "$1" in
  status)
    echo "$code $proc" | awk '{code=$1}{proc=$2}END{if(code == "200" && proc != 0){printf("%d
",1)}else{printf("%d
",0)}}'
    ;;
  active)
    echo "$info" | awk '/^Active/{var=$NF}END{if(var~/^[0-9]+$/){printf("%d
",var)}else{printf("%d
",0)}}'
    ;;
  reading)
    echo "$info" | awk '/Reading/ {print $2}'
    ;;
  writing)
    echo "$info" | awk '/Writing/ {print $4}'
    ;;
  waiting)
    echo "$info" | awk '/Waiting/ {print $6}'
    ;;
  accepts)
    echo "$info" | awk 'NR==3 {print $1}'
    ;;
  handled)
    echo "$info" | awk 'NR==3 {print $2}'
    ;;
  requests)
    echo "$info" | awk 'NR==3 {print $3}'
    ;;
  restimes)
    echo "$info" | awk 'BEGIN{OFMT="%.3f"} NR==3 {print $4/$3}'
    ;;
  *)
    echo "ZBX_NOTSUPPORTED"
    ;;
esac
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# vim /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh

2>.修改自定义的监控脚本权限

使用Zabbix监控Nginx状态页实战案例第26张使用Zabbix监控Nginx状态页实战案例第27张
[root@nginx201.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/
total 4
-rw-r--r-- 1 root root 1092 Feb 21 23:42 check_nginx.sh
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# chmod +x /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# ll /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/
total 4
-rwxr-xr-x 1 root root 1092 Feb 21 23:42 check_nginx.sh
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# chmod +x /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh

3>.修改zabbix agent的配置文件让其支持自定义监控项功能

使用Zabbix监控Nginx状态页实战案例第28张使用Zabbix监控Nginx状态页实战案例第29张
[root@nginx201.yinzhengjie.org.cn ~]# grep "# UserParameter=" /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
# UserParameter=
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i "s@# (UserParameter=)@1nginx.status[*],/yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh $1 $2 $3@" /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# grep "^UserParameter=" /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
UserParameter=nginx.status[*],/yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh $1 $2 $3
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# sed -r -i "s@# (UserParameter=)@1nginx.status[*],/yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf.d/check_nginx.sh $1 $2 $3@" /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf

4>.重启zabbix agent服务使得配置生效

使用Zabbix监控Nginx状态页实战案例第30张使用Zabbix监控Nginx状态页实战案例第31张
[root@nginx201.yinzhengjie.org.cn ~]# ps -ef | grep zabbix
zabbix    20587      1  0 00:01 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
zabbix    20588  20587  0 00:01 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    20589  20587  0 00:01 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    20590  20587  0 00:01 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    20591  20587  0 00:01 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    20592  20587  0 00:01 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      20677  20440  0 00:02 pts/1    00:00:00 grep --color=auto zabbix
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# ss -ntl
State      Recv-Q Send-Q                                                                                          Local Address:Port                                                                                                         Peer Address:Port              
LISTEN     0      128                                                                                                         *:111                                                                                                                     *:*                  
LISTEN     0      511                                                                                                         *:80                                                                                                                      *:*                  
LISTEN     0      128                                                                                                         *:22                                                                                                                      *:*                  
LISTEN     0      128                                                                                                         *:10050                                                                                                                   *:*                  
LISTEN     0      128                                                                                                        :::22                                                                                                                     :::*                  
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent.service 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# ss -ntl
State      Recv-Q Send-Q                                                                                          Local Address:Port                                                                                                         Peer Address:Port              
LISTEN     0      128                                                                                                         *:111                                                                                                                     *:*                  
LISTEN     0      511                                                                                                         *:80                                                                                                                      *:*                  
LISTEN     0      128                                                                                                         *:22                                                                                                                      *:*                  
LISTEN     0      128                                                                                                         *:10050                                                                                                                   *:*                  
LISTEN     0      128                                                                                                        :::22                                                                                                                     :::*                  
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# ps -ef | grep zabbix
zabbix    20689      1  0 00:03 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd -c /yinzhengjie/softwares/zabbix/etc/zabbix_agentd.conf
zabbix    20690  20689  0 00:03 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    20691  20689  0 00:03 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    20692  20689  0 00:03 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    20693  20689  0 00:03 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    20694  20689  0 00:03 ?        00:00:00 /yinzhengjie/softwares/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      20697  20440  0 00:03 pts/1    00:00:00 grep --color=auto zabbix
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# 
[root@nginx201.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent.service

5>.在zabbix server端使用zabbix_get命令行进行测试

[root@zabbix203.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s nginx201.yinzhengjie.org.cn -p 10050 -k "nginx.status[status]"

使用Zabbix监控Nginx状态页实战案例第32张

四.自定义Nginx的监控模板

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie2020/p/12340063.html

五.使用自定义的Nginx模板监控nginx服务

1>.点击创建主机

使用Zabbix监控Nginx状态页实战案例第33张

2>.填写nginx的主机监控信息

使用Zabbix监控Nginx状态页实战案例第34张

3>.选择咱们自定义的Nginx监控模板

使用Zabbix监控Nginx状态页实战案例第35张

4>.如下图所示,点击"添加"按钮,添加链接的模板

使用Zabbix监控Nginx状态页实战案例第36张

5>.为Nginx主机关联多个模板并点击"添加"按钮

使用Zabbix监控Nginx状态页实战案例第37张

6>.主机模板添加成功

使用Zabbix监控Nginx状态页实战案例第38张

7>.nginx主机监控成功

使用Zabbix监控Nginx状态页实战案例第39张

8>.查看nginx模板的图形

使用Zabbix监控Nginx状态页实战案例第40张

免责声明:文章转载自《使用Zabbix监控Nginx状态页实战案例》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SpringBoot 2 要不要升级获取Android版本下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

配置Nginx和Apache允许指定域名CORS跨域访问

 前后端分离开发,导致前端项目需要跨域请求后端接口,解决方法有很多,本文只介绍两个: 1. 修改后端程序代码实现允许跨域请求 2. 修改服务器配置文件实现允许跨域请求 正文: 方法1:修改后端程序代码实现允许跨域请求  以ThinkPHP为例,为了一劳永逸,直接在入口文件index.php中加入代码: header("Access-Control-Allo...

VMWare Esxi 6.5(实际为5.x,6.x)时区问题

Esxi不支持修改时区,但是可以使用ESX或者Centos 6/7的localtime文件进行替换以实现时区修改,问题是,重启后文件会被还原。 详细的纠结过程就不说了,终级解决方案如下(给公司写的,现分享出来): 大概思路是:将centos 6中/usr/share/zoneinfo/Asia/Shanghai文件(如果是它国时区,请自行替换base64内...

Supervisor安装与配置

参考https://www.cnblogs.com/morgana/p/8908723.html Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。...

Django 部署到Nginx

在网上搜了很多篇Django+uwsgi+Nginx的部署文章,忙了一下午头昏脑胀,最终完成了部署。部署文章流程讲解都很好,但在细节上或许缺乏一些注意力,导致我多篇文章来回切换在字里行间寻找蛛丝马迹。既然我完成了部署,那我何不写下自己的流程和心得,让后来人有一些参考? 原理 Django+uwsgi+Nginx的工作模式如下图所示,三个服务各司其职,分别为...

Mac使用nginx+rtmp服务器

一、安装Homebrow 已经安装了brow的可以直接跳过这一步。执行命令 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 如果已经安装过,而想要卸载: ruby -e "$(curl -fsSL https://raw.gi...

HTTP方式播放FLV/mp4 :nginx+Yamdi/MP4BOX

【导语】chrome浏览器确实很强,直接支持MP4拖动播放,对于其他播放器,可以使用以下方法来支持拖动播放。拖动的关键在于生成关键帧等元数据信息,便于服务器和播放器支持拖动。 另外,nginx web服务器体验起来,也是很有前途的一个web服务器,值得研究。 flv 视频可以采用两种方式发布: 一、普通的 HTTP 下载方式 二、基于 Flash Medi...