zabbix4.2配置监控nginx服务
1.监控原理
通过status模块监控(--with-http_stub_status_module)

2.修改nginx配置(/etc/nginx/conf.d/default.conf)
在被监控的主机上修改nginx配置文件,在配置文件中添加(一个location)下面的内容,修改后记得重启nginx服务:
location /nginx_status {
stub_status on;
allow 192.168.10.100; #表示允许该主机访问url:http://192.168.10.100/nginx_status
allow 192.168.10.2;
access_log off;
}
3.添加监控脚本
在nginx服务器主机上添加监控nginx脚本(/etc/zabbix/zabbix_agent.d/nginx_status.sh,同时赋予该脚本可执行权限chmod a+x nginx_status.sh
#!/bin/bash
#Script to fetch nginx statuses for monitoring systems
HOST="192.168.10.100" #IP地址为装有nginx服务的主机地址
PORT="80" function ping {
/sbin/pidof nginx | wc -l
} function active {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
$1
4.进行访问测试检测
[root@zabbix-server-center alertscripts]# curl http://192.168.10.100/nginx_status #IP地址为nginx服务器的主机地址
Active connections: 1
server accepts handled requests
1 1 1
Reading: 0 Writing: 1 Waiting: 0
5.检测脚本测试
关于nginx状态的一些概念:
Active connections Nginx正处理的活动链接数个数;重要
server Nginx启动到现在共处理了多少个连接。
accepts Nginx启动到现在共成功创建几次握手。
handled requests Nginx总共处理了几次请求。
Reading Nginx读取到客户端的 Header 信息数。
Writing Nginx返回给客户端的 Header 信息数。
Waiting Nginx已经处理完正在等候下一次请求指令的驻留链接,开启。
Keep-alive的情况下,Waiting这个值等于active-(reading + writing)。
请求丢失数=(握手数-连接数)可以看出,本次状态显示没有丢失请求。
[root@zabbix-server-center alertscripts]# sh nginx_status.sh active
1
[root@zabbix-server-center alertscripts]# sh nginx_status.sh reading
0
[root@zabbix-server-center alertscripts]# sh nginx_status.sh writing
1
[root@zabbix-server-center alertscripts]# sh nginx_status.sh accepts
20
6.在装有nginx服务的主机上修改zabbix_agentd.conf配置文件(/etc/zabbix/zabbix_agentd.conf)
修改:UnsafeUserParameters 等于 1 :UnsafeUserParameters=1
7.添加zabbix配置文件,放于 /etc/zabbix/zabbix_agentd.d/目录下(agent的配置文件 /etc/zabbix/zabbix_agentd.conf 中定义了其他key的包含目录)创建配置文件nginx_status.conf
添加:UserParameter=nginx[*], /etc/zabbix/zabbix_agentd.d/nginx_status.sh $1
#后面路径是监控脚本的位置

8.重启zabbix-agent服务
[root@ansible-control zabbix_agentd.d]# systemctl restart zabbix-agent.service
9.在zabbix server服务器上测试,是否能正常获取数据
[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[ping]
1
[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[requests]
2304
[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[accepts]
6285
[root@zabbix-server-center /]# zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[handled]
6286
7.进入zabbix界面配置监控模板
(1)创建模板:

(2)添加应用集:

(3)创建监控项:

(4)创建多个监控项:

(5)创建触发器:触发器实时监控 Nginx 的存活状态,Nginx 一旦 Dump 机,就会发生报警。

(6)创建图形:

8.将模板应用在装有Nginx服务的主机

9.查看监控图形

10.如果刚开始数值比较小,不利于查看图形,可以使用ab进行简单的压力测试(主要是requests),再查看数值变化
-n:在测试会话中所执行的请求个数。默认时,仅执行一个请求。
-c:一次产生的请求个数。默认是一次一个。
[root@zabbix-server-center /]# ab -n 1000 -c 1000 http://192.168.10.100:80/nginx_status
[root@zabbix-server-center /]# ab -n 1000 -c 1000 http://192.168.10.100:80/nginx_status
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.10.100 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests Server Software: nginx/1.17.1
Server Hostname: 192.168.10.100
Server Port: 80 Document Path: /nginx_status
Document Length: 106 bytes Concurrency Level: 1000
Time taken for tests: 0.331 seconds
Complete requests: 1000
Failed requests: 819
(Connect: 0, Receive: 0, Length: 819, Exceptions: 0)
Write errors: 0
Total transferred: 253092 bytes
HTML transferred: 109092 bytes
Requests per second: 3016.63 [#/sec] (mean)
Time per request: 331.496 [ms] (mean)
Time per request: 0.331 [ms] (mean, across all concurrent requests)
Transfer rate: 745.59 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 3 31 15.1 26 69
Processing: 26 90 68.1 62 253
Waiting: 1 90 68.2 62 253
Total: 72 121 64.4 91 282 Percentage of the requests served within a certain time (ms)
50% 91
66% 103
75% 109
80% 113
90% 239
95% 280
98% 282
99% 282
100% 282 (longest request)

值得参考的帖子:https://cloud.tencent.com/developer/article/1400917
11.关于Nginx的一个告警测试
进入模板选择nginx-status模板,添加触发器,表示requests大于500就发送邮件报警。

在zabbix服务器上使用ab命令进行疯狂压力测试(发送requests请求),不一会requests请求就超过500,随后就会收到报警邮件。
[root@zabbix-server-center /]# ab -n 1000 -c 1000 http://192.168.10.100:80/nginx_status

zabbix4.2配置监控nginx服务的更多相关文章
- 【zabbix告警监控】配置zabbix监控nginx服务
zabbix监控nginx,nginx需要添加--with-http_stub_status模块 使用zabbix监控nginx,首先nginx需要配置开启ngx_status.但是我这边nginx安 ...
- 使用Zabbix监控Nginx服务实战案例
使用Zabbix监控Nginx服务实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.编译安装nginx步骤详解并开启状态页 博主推荐阅读: https://www.cn ...
- Nagios监控nginx服务具体过程
1在nginx 服务器上安装nrpe客户端: Nginx的服务须要监控起来.不然万一down了而不及时修复,会影响web应用.例如以下web应用上面启动的nginx后台进程[root@lb-net-2 ...
- Python 监控nginx服务是否正常
Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...
- 监控nginx服务
转自:http://www.cnblogs.com/silent2012/p/5310500.html 在Nginx的插件模块中有一个模块stub_status可以监控Nginx的一些状态信息,默认安 ...
- ZABBIX 3.0 配置监控NGINX性能【OK】
1.在agent端查看配置: nginx -V //查看编辑时是否加入状态监控模块:--with-http_stub_status_module --with-http_gzip_static_mod ...
- zabbix监控nginx服务状态
nginx需要安装--with-http_stub_status_module模块 $ nginx -V nginx version: nginx/1.12.2 built by gcc 4.8.5 ...
- 监控Nginx服务的Shell脚本
Nginx 虽然处理并发量比 apache 确实要强点,但它这种 php-cgi 模式不是太稳定,这点网上也有朋友总结了,我在实现项目中也感受到了. 我们一台支付机,偶尔会出现以下情况的:php-cg ...
- cacti系列(一)之cacti的安装及配置监控mysql服务
简介 Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数.它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构 ...
随机推荐
- zabbix默认监控负载取值不准确
今天碰到个负载高引起的问题但是查看zabbix监控并没有报警,检查后发现监控取值与实际服务器内负载不一致. 使用zabbix_get命令在服务器内测试 zabbix默认模板键值 取值内容 [root@ ...
- DC-8靶机渗透实战
前言: 本文将讲述通过信息收集,再web站点的sql注入漏洞加john爆破登录后台,然后找到远程代码执行漏洞getshell,最后用exim4命令提权漏洞进行权限提升拿到最终的flag. 0x00 环 ...
- [Python]PyCharm中%matplotlib inline报错
%matplotlib作用 是在使用jupyter notebook 或者 jupyter qtconsole的时候,才会经常用到%matplotlib,也就是说那一份代码可能就是别人使用jupyte ...
- js磁力线代码(非压缩,自己在压缩的版本上优化了代码,易于阅读)
拿去白嫖吧: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=" ...
- linux安装Nginx 以及 keepalived 管理Nginx
linux安装Nginx 1.1将Nginx素材内容上传到/usr/local目录(pcre,zlib,openssl,nginx)(注意:必须登录用对这个文件具有操作权限的) 1.2安装pcre库 ...
- 项目在UAP可以直接启动,但是在eclipse上面不能直接启动
上面两个eclipse都是用友的开发人员给我的,左边是驻场开发给我的,但是没有教我怎么用和哪里好用,所以一直用UAP来做开发.右边的eclipse是提ISM问题,北京用友远程调试问题时给我的,而且终于 ...
- Spark学习之路 (六)Spark Transformation和Action[转]
Transformation算子 基本的初始化 (1)java static SparkConf conf = null; static JavaSparkContext sc = null; sta ...
- jquery click事件中的return false
提交表单数据时设定了type="submit"属性,单击提交按钮后会默认刷新页面 但是在使用jquery的click事件时没出现跳转 $('button').click(funct ...
- 剑指offer-面试题17-打印从1到最大的n位数-数字
/* 题目: 输入数字n,按顺序打印从1到最大的n位十进制数. 如输入3,打印从1,2,3到999. */ /* 思路: 大数问题转化为字符串或数组. */ #include<iostream& ...
- js返回时间差
function CalcTimeSub(endTime, startTime, type) { var bool = endTime == defaultDateTime || startTime ...