微信搜索superit|邀请体验:大数据, 数据管理、OLAP分析与可视化平台 | 赞助作者:赞助作者

Zabbix 4.4(五)zabbix监控nginx(自定义nginx监控选项)

zabbix aide_941 2℃ 0评论

实验环境

  1. zabbix-server:
  2. centos 7
  3. 192.168.14.216
  4. nginx
  5. centos7
  6. 192.168.14.210

介绍:

zabbix默认带有两个nginx的模板,可以直接链接模板使用。本文主要介绍根据实际情况自定义一些监控选项

一、Nginx(192.168.14.210)

1、安装

  1. #配置epel源
  2. [root@nginx ~]# vi /etc/yum.repos.d/epel.repo
  3. [nginx]
  4. name=aliyun epel
  5. baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
  6. gpgcheck=0
  7. #安装nginx
  8. [root@nginx ~]# yum install -y nginx
  9. #安装zabbix-agent
  10. [root@nginx ~]# rpm -ivh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
  11. [root@nginx ~]# yum install -y zabbix-agent

2、修改nginx配置文件,为了不影响默认/,添加新的/status

  1. [root@nginx ~]# vim /etc/nginx/nginx.conf
  2. location /status {
  3. stub_status on;
  4. access_log off;
  5. allow 127.0.0.1;
  6. deny all;
  7. }

3、查看监控内容

Active  connections:当前所有处于打开状态的活动连接数(TCP连接数,即三次握手四次挥手次数)
accepts :已经接收连接数
handled : 已经处理过的连接数
requests : 已经处理过的请求数,在保持连接模式下,请求数量可能会大于连接数量
Reading: 正处于接收请求的连接数
Writing: 请求已经接收完成,处于响应过程的连接数
Waiting : 保持连接模式,处于活动状态的连接数

4、添加nginx监控选项

  1. #拷贝自带的mysql配置文件并修改为nginx
  2. [root@nginx ~]# cd /etc/zabbix/zabbix_agentd.d/
  3. [root@nginx zabbix_agentd.d]# cp userparameter_mysql.conf userparameter_nginx.conf
  4. #删除有关mysql数据,添加nginx监控选项
  5. [root@nginx zabbix_agentd.d]# vi userparameter_nginx.conf
  6. UserParameter=nginx.active,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Active’ | awk ‘{print $NF}’
  7. UserParameter=nginx.reading,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Reading’ | awk ‘{print $2}’
  8. UserParameter=nginx.writing,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Writing’ | awk ‘{print $4}’
  9. UserParameter=nginx.waiting,curl -s http://127.0.0.1/status 2>/dev/null| grep ‘Waiting’ | awk ‘{print $6}’
  10. UserParameter=nginx.accepts,curl -s http://127.0.0.1/status 2>/dev/null| awk NR==3 | awk ‘{print $1}’
  11. UserParameter=nginx.handled,curl -s http://127.0.0.1/status 2>/dev/null| awk NR==3 | awk ‘{print $2}’
  12. UserParameter=nginx.requests,curl -s http://127.0.0.1/status 2>/dev/null| awk NR==3 | awk ‘{print $3}’

5、开启服务

  1. [root@nginx ~]# systemctl start nginx
  2. [root@nginx ~]# systemctl start zabbix-agent

6、防火墙允许端口访问

  1. [root@nginx ~]# firewall-cmd –permanent –zone=public –add-port=80/tcp
  2. [root@nginx ~]# firewall-cmd –permanent –zone=public –add-port=10050/tcp
  3. [root@nginx ~]# firewall-cmd –reload

二、zabbix-server(192.168.14.216)

1、检查是否安装zabbi_get

  1. [root@zabbix_server ~]# docker ps -a
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. e2e2a132cd5d zabbix/zabbix-agent:centos-latest “/sbin/tini — /usr/…” 25 hours ago Up 25 hours zabbix_zabbix-agent_1
  4. f1e1da5d9083 zabbix/zabbix-web-apache-mysql:centos-latest “docker-entrypoint.sh” 25 hours ago Up 25 hours (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp zabbix_zabbix-web-apache-mysql_1
  5. f96412915d59 zabbix/zabbix-server-mysql:centos-latest “/sbin/tini — /usr/…” 25 hours ago Up 25 hours 0.0.0.0:10051->10051/tcp zabbix_zabbix-server_1
  6. dd4a1123fa5d mysql:5.7 “docker-entrypoint.s…” 30 hours ago Up 25 hours zabbix_mysql-server_1
  7. 9a4c101679e2 zabbix/zabbix-snmptraps:centos-latest “/usr/bin/supervisor…” 30 hours ago Up 25 hours 0.0.0.0:162->162/udp zabbix_zabbix-snmptraps_1
  8. [root@zabbix_server ~]# docker exec -it zabbix_zabbix-server_1 /bin/bash
  9. [root@f96412915d59 zabbix]# zabbix_get -s 192.168.14.210 -p 10050 -k ‘nginx.active’
  10. 1

2、添加监控选项(依次创建七个监控选项)


3、查看创建

4、创建图形

5、添加图形监控项

6、查看图形结果

转载请注明:SuperIT » Zabbix 4.4(五)zabbix监控nginx(自定义nginx监控选项)

喜欢 (0)or分享 (0)

您必须 登录 才能发表评论!