栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

zabbix监控nginx状态

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zabbix监控nginx状态

zabbix监控nginx 环境说明:
环境IP地址安装的服务
服务器:server1192.168.244.144lamp架构
zabbix server
zabbix agent
客户端:test192.168.244.133zabbix agent
nginx

在客户端部署zabbix agent

[root@node1 bag]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.4.tar.gz

[root@node1 bag]# ls
zabbix-5.4.4.tar.gz


#解压
[root@node1 bag]# tar xf zabbix-5.4.4.tar.gz -C  /usr/local/

安装依赖包和编译器

[root@node1 ~]#  yum -y install vim  wget gcc gcc-c++ make pcre-devel

创建用户

[root@node1 ~]#  useradd -r -M -s /sbin/nologin zabbix
[root@node1 ~]# id zabbix
uid=989(zabbix) gid=986(zabbix) groups=986(zabbix)

进入包编译安装

[root@node1 zabbix-5.4.4]# cd  /usr/local/zabbix-5.4.4/
[root@node1 zabbix-5.4.4]#  ./configure --enable-agent
......
......
  LDAP support:          no
  IPv6 support:          no

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*                                  *
***********************************************************
[root@node1 zabbix-5.4.4]# make install
......
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/usr/local/zabbix-5.4.4'
make[1]: Leaving directory '/usr/local/zabbix-5.4.4'

修改配置文件

[root@node1 zabbix-5.4.4]# cd /usr/local/etc/
[root@node1 etc]# vim  zabbix_agentd.conf


Server=192.168.244.144  #server1 IP

......
ServerActive=192.168.244.144

.....
Hostname=tom   #名字随便改

配置service文件可开机自启

[root@node1 etc]# vim  zabbix_agentd.conf
[root@node1 etc]# cd  /usr/lib/systemd/system/
[root@node1 system]#  vim  zabbix_agentd.service
[root@node1 system]# cat zabbix_agentd.service
[Unit]
Description=zabbix agent daemon
After=network.target 

[Service]
Type=forking

ExecStart=/usr/local/sbin/zabbix_agentd 
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@node1 system]# systemctl  daemon-reload
[root@node1 system]# systemctl enable --now zabbix_agentd
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_agentd.service → /usr/lib/systemd/system/zabbix_agentd.service.
[root@node1 system]# zabbix_agentd 
[root@node1 system]# 
[root@node1 system]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port                      Peer Address:Port                 
LISTEN   0        128               0.0.0.0:80                             0.0.0.0:*                    
LISTEN   0        128               0.0.0.0:22                             0.0.0.0:*                    
LISTEN   0        128               0.0.0.0:443                            0.0.0.0:*                    
LISTEN   0        128               0.0.0.0:10050                          0.0.0.0:*                    
LISTEN   0        128                  [::]:22                                [::]:*                    
LISTEN   0        80                      *:3306                                 *:*   
开启状态界面

开启status:

location /status {
  stub_status {on | off};
  allow 172.16.0.0/16;
  deny all;
}

访问状态页面的方式:http://server_ip/status

状态页面信息详解:

状态码表示的意义
Active connections 2当前所有处于打开状态的连接数
accepts总共处理了多少个连接
handled成功创建多少握手
requests总共处理了多少个请求
Readingnginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数
Writingnginx返回给客户端的Header信息数,表示请求已经接收完成, 且正处于处理请求或发送响应的过程中的连接数
Waiting开启keep-alive的情况下,这个值等于active - (reading + writing), 意思就是Nginx已处理完正在等候下一次请求指令的驻留连接

在nginx.conf

        location /status {
            stub_status off;
            allow 192.168.244.144;
            allow 192.168.244.0/24;
            deny all;
        }

[root@node1 ~]# nginx -s reload

访问

[root@node1 ~]# curl 192.168.244.133/status
Active connections: 3 
server accepts handled requests
 31 31 23 
Reading: 0 Writing: 1 Waiting: 2 

编写脚本

[root@node1 scripts]# pwd
/scripts

[root@node1 scripts]# cat check_Reading.sh 
#!/bin/bash
Reading=$( curl -s 192.168.244.133/status |awk 'NR==4 {print$2}' )

if [ $Reading -gt 3 ];then
            echo '1'
    else
            echo '0'
fi

[root@node1 scripts]# cat check_Writing.sh 
#! /bin/bash

Writing=$( curl -s 192.168.244.133/status |awk 'NR==4 {print$4}' )

if [ $Writing -gt 0 ];then
            echo '1'
    else
            echo '0'
fi
[root@node1 scripts]# ./check_Reading.sh 
0
[root@node1 scripts]# ./check_Writing.sh 
1
      
[root@node1 ~]# vim /usr/local/etc/zabbix_agentd.conf

........
UnsafeUserParameters=1
UserParameter=check_Reading,/scripts/check_Reading.sh
UserParameter=check_Writing,/scripts/check_Writing.sh
UserParameter=check_Waiting,/scripts/check_Waiting.sh



[root@node1 ~]# zabbix_agentd 

zabbix_server服务端测试

[root@localhost ~]# zabbix_get -s 192.168.244.133 -k check_Reading
0


[root@localhost ~]# zabbix_get -s 192.168.244.133 -k check_Writing
1

访问zabbix_server服务端









测试

[root@localhost ~]# yum -y install httpd-tools

[root@localhost ~]#  ab -n 15000 http://192.168.244.133/status
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.244.133 (be patient)
Completed 1500 requests
Completed 3000 requests
Completed 4500 requests
Completed 6000 requests
Completed 7500 requests
Completed 9000 requests
Completed 10500 requests
Completed 12000 requests
Completed 13500 requests
Completed 15000 requests
Finished 15000 requests


Server Software:        nginx/1.20.1
Server Hostname:        192.168.244.133
Server Port:            80

document Path:          /status
document Length:        115 bytes

Concurrency Level:      1
Time taken for tests:   3.887 seconds
Complete requests:      15000
Failed requests:        0
Total transferred:      3885000 bytes
HTML transferred:       1725000 bytes
Requests per second:    3858.65 [#/sec] (mean)
Time per request:       0.259 [ms] (mean)
Time per request:       0.259 [ms] (mean, across all concurrent requests)
Transfer rate:          975.97 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       4
Processing:     0    0   0.0      0       1
Waiting:        0    0   0.0      0       1
Total:          0    0   0.1      0       4

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      0
  98%      0
  99%      0
 100%      4 (longest request)
[root@localhost ~]# 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361782.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号