zabbix监控Nginx的各项指标步骤详解

自定义监控Nginx的各项指标

一、被监控端agent安装Nginx

1、安装Nginx

访问nginx的官方网站:<http://www.nginx.org/>
#vim   /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true    //配置Nginx软件包文件
[root@nginx-server yum.repos.d]# yum install -y nginx   //安装Nginx
[root@nginx-server yum.repos.d]# nginx -V   //查看安装模块及版本号
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

2、关闭放防火墙

[root@nginx-server ~]# getenforce 
Enforcing

[root@nginx-server ~]# setenforce 0

[root@nginx-server ~]# systemctl stop firewalld
[root@nginx-server ~]# systemctl disable firewalld

3、启动并设置开机自启

[root@nginx-server ~]# systemctl start nginx 
[root@nginx-server ~]# systemctl enable nginx 

4、运用浏览器输入IP进行访问,是否安装成功

5、用法命令查找监控模块

# -V大写会显示版本号和模块等信息、v小写仅显示版本信息
[root@localhost ~]# nginx -V

./configure –with-http_stub_status_module   //是否有此模块

6、配置Nginx子文件

#vim /etc/nginx/conf.d/default.conf
server {
        listen 80;
        server_name localhost;
        location /ngx-status {
                stub_status     on;
                access_log      on;
                }
}

7、配置完成后在浏览器中输入http://192.168.239.143/nginx-status 查看

(或者用 `curl localhost/nginx

-status),显示信息如下:

Active connections: 2 
server accepts handled requests
 26 26 48 
Reading: 0 Writing: 1 Waiting: 1    //查看是否访问的到

9、修改agent被监控端的配置,设置用户参数

[root@zabbix-agent-none1 ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@zabbix-agent-none1 zabbix_agentd.d]# vim memory_usage.conf
serParameter=Nginx.Accepts.Connections,/usr/bin/curl -s http://192.168.239.143/ngx_status 2>/dev/null|sed -n '3p'|awk '{print $1}'
#监控Nginx处理连接失败数
UserParameter=Nginx.Handled.Connections,/usr/bin/curl -s http://1192.168.239.143/ngx_status 2>/dev/null|sed -n '3p'|awk '{print $2}'
#监控Nginx处理请求总数
UserParameter=Nginx.requests.Connections,/usr/bin/curl -s http://192.168.239.143/ngx_status 2>/dev/null|sed -n '3p'|awk '{print $3}'
#Nginx读取到客户端的Header信息数
UserParameter=Nginx.Reading,/usr/bin/curl -s http://192.168.239.143/ngx_status 2>/dev/null|sed -n '4p'|awk '{print $2}'
#Nginx返回给客户端的Header信息数
UserParameter=Nginx.Writing,/usr/bin/curl -s http://192.168.239.143/ngx_status 2>/dev/null|sed -n '4p'|awk '{print $4}'
#Nginx处理完并等候状态的驻留连接
UserParameter=Nginx.Waiting,/usr/bin/curl -s http://192.168.239.143/ngx_status 2>/dev/null|sed -n '4p'|awk '{print $6}'

10、重启agent

[root@zabbix-agent-none1 zabbix_agentd.d]# systemctl restart zabbix-agent.service

11、在zabbix-server监控端查询

[root@zabbix-server fonts]# zabbix_get -s 192.168.239.143 -p 10050 -k "Nginx.Accepts.Connections"

在这里插入图片描述
12、在监控上,设置一个item监控项,使用这个用户参数

配置–>主机–>none1–>创建应用集–>监控项–>创建监控项
zabbix监控Nginx的各项指标步骤详解_第1张图片
zabbix监控Nginx的各项指标步骤详解_第2张图片
监测中–>最新数据–> Nginx应用集–>最新数据–>图形
zabbix监控Nginx的各项指标步骤详解_第3张图片

你可能感兴趣的:(运维工程师,nginx)