1.安装nginx

[root@client-zabbix ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@client-zabbix ~]# yum -y install nginx
[root@client-zabbix ~]# systemctl enable nginx
[root@client-zabbix ~]# systemctl start nginx

访问nginx服务:http://192.168.1.63

Zabbix监控Nginx并发_自定义


Zabbix监控Nginx并发_自定义_02


Zabbix监控Nginx并发_自定义_03

Zabbix监控Nginx并发_vim_04

监控nginx的并发

1.开启nginx状态页面

[root@client-zabbix ~]# vim /etc/nginx/nginx.conf
...
 location /status {
                stub_status on;
        }

[root@client-zabbix ~]# systemctl restart nginx
[root@client-zabbix ~]# curl http://192.168.1.63/status
Active connections: 1 
server accepts handled requests
 1 1 1 
Reading: 0 Writing: 1 Waiting: 0

2.只获取当前活动链接数的值

[root@client-zabbix ~]# curl http://192.168.1.63/status  2> /dev/null | grep Active | awk '{print $3}'
1

3.修改zabbix-agent端配置文件开启自定义功能

[root@client-zabbix ~]# vim /etc/zabbix/zabbix_agentd.conf 
...
Include=/etc/zabbix/zabbix_agentd.d/*.conf    //脚本存放路径
UnsafeUserParameter=1     //开启自定义监控
[root@client-zabbix ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@client-zabbix zabbix_agentd.d]# vim nginx_connection.conf
UserParameter=nginx_connection,curl http://192.168.1.63/status 2> /dev/null | grep Active | awk '{print $3}'

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

zabbix-server上使用zabbix-get测试

[root@server-zabbix ~]# yum -y install zabbix-get

命令行取值

[root@server-zabbix ~]# zabbix_get -s 192.168.1.63 -k nginx_connection
1

Zabbix监控Nginx并发_nginx_05


Zabbix监控Nginx并发_自定义_06


Zabbix监控Nginx并发_nginx_07

Zabbix监控Nginx并发_自定义_08


Zabbix监控Nginx并发_nginx_09

Zabbix监控Nginx并发_nginx_10


Zabbix监控Nginx并发_nginx_11


Zabbix监控Nginx并发_nginx_12


Zabbix监控Nginx并发_vim_13


Zabbix监控Nginx并发_自定义_14


Zabbix监控Nginx并发_nginx_15


Zabbix监控Nginx并发_vim_16


Zabbix监控Nginx并发_vim_17


查看最终效果

Zabbix监控Nginx并发_nginx_18