老谢博客

  • 首页
  • WordPress
  • 网络技术
  • 乱七八糟
  • 运维技术
  • 给我留言
  • 关于老谢

Zabbix 3.2 agentd监控Nginx性能

分类:运维技术日期:2018-06-11 - 13:00:59作者:老谢

#nginx需要编译http_stub_status_module模块,编译参数:with-http_stub_status_module
#确保curl localhost/nginx_status输出如下:
 
[root@iZ237lzm354Z scripts]# curl www.baidu.com/nginx-status
Active connections: 979 
server accepts handled requests
 756072922 756072922 1136799890 
Reading: 0 Writing: 4 Waiting: 975
 
#Active connections –当前活跃的连接数量  
#server accepts handled requests — 总共处理了756072922个连接 , 成功创建 756072922次握手, 总共处理了1136799890个请求
#reading — 读取客户端的连接数.
#writing — 响应数据到客户端的数量
#waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

#nginx需要编译http_stub_status_module模块,编译参数:with-http_stub_status_module #确保curl localhost/nginx_status输出如下: [root@iZ237lzm354Z scripts]# curl www.baidu.com/nginx-status Active connections: 979 server accepts handled requests 756072922 756072922 1136799890 Reading: 0 Writing: 4 Waiting: 975 #Active connections –当前活跃的连接数量 #server accepts handled requests — 总共处理了756072922个连接 , 成功创建 756072922次握手, 总共处理了1136799890个请求 #reading — 读取客户端的连接数. #writing — 响应数据到客户端的数量 #waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

开启nginx_status
 server {
                        listen       80 ;
                        server_name  www.baidu.com; 
           rewrite ^/invitejoin/(.*)\.htm[l]?$  /register.shtml?$1 last; 
                 index index.jsp index.html;
                 root /opt/home;
            location = /nginx-status {
                              stub_status on;
                              access_log  off;
                              allow 127.0.0.1;
                              allow 10.253.12.34; 
                             ####zabbix服务器端的IP地址一般为内网IP
                               }

server { listen 80 ; server_name www.baidu.com; rewrite ^/invitejoin/(.*)\.htm[l]?$ /register.shtml?$1 last; index index.jsp index.html; root /opt/home; location = /nginx-status { stub_status on; access_log off; allow 127.0.0.1; allow 10.253.12.34; ####zabbix服务器端的IP地址一般为内网IP }

性能状态描述

  NGINX worker 进程接受 OS 的连接请求时 Accepts 计数器增加,而Handled 是当实际的请求得到连接时(通过建立一个新的连接或重新使用一个空闲的)。这两个计数器的值通常都是相同的,如果它们有差别则表明连接被Dropped, 往往这是由于资源限制,比如已经达到 NGINX 的worker_connections的限制。

名称
描述
指标类型
Accepts(接受)
NGINX 所接受的客户端连接数
资源: 功能
Handled(已处理)
成功的客户端连接数
资源: 功能
Active(活跃)
当前活跃的客户端连接数
资源: 功能
Dropped(已丢弃,计算得出)
丢弃的连接数(接受 – 已处理)
工作:错误*
Requests(请求数)
客户端请求数
工作:吞吐量
配置zabbix_agentd
mkdir /usr/local/zabbix/share/scripts
vim /usr/local/zabbix/share/scripts/nginx-check_performance.sh
 
#!/bin/bash
##################################
# Zabbix monitoring script
#
# nginx:
# - anything available via nginx stub-status module
#
##################################
# Contact:
# vincent.viallet@gmail.com
# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"
# Nginx defaults
NGINX_STATUS_DEFAULT_URL="127.0.0.1/nginx_status"    #(这里写网站的域名)
WGET_BIN="/usr/bin/wget"
#
# Error handling:
# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
# - items need to be of type "float" (allow negative + float)
#
ERROR_NO_ACCESS_FILE="-0.9900"
ERROR_NO_ACCESS="-0.9901"
ERROR_WRONG_PARAM="-0.9902"
ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
# Handle host and port if non-default
if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
 URL="$ZBX_REQ_DATA_URL"
else
 URL="$NGINX_STATUS_DEFAULT_URL"
fi
# save the nginx stats in a variable for future parsing
NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
 echo $ERROR_DATA
 exit 1
fi
#
# Extract data from nginx stats
#
case $ZBX_REQ_DATA in
 active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';;
 accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';;
 handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';;
 handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';;
 reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';;
 writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';;
 waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';;
 *) echo $ERROR_WRONG_PARAM; exit 1;;
esac
exit 0
 
chmod +x /usr/local/zabbix/share/scripts/nginx-check_performance.sh
chown zabbix:zabbix /usr/local/zabbix/share/scripts/nginx-check_performance.sh
 
vim /usr/local/zabbix/etc/zabbix_agentd.conf
#找到 #UserParameter= ,删除注释,修改为:nginx[*],/usr/local/zabbix/share/scripts/nginx-check_performance.sh "$1"
/etc/init.d/zabbix_agentd start
#防火墙需允许10050端口

mkdir /usr/local/zabbix/share/scripts vim /usr/local/zabbix/share/scripts/nginx-check_performance.sh #!/bin/bash ################################## # Zabbix monitoring script # # nginx: # - anything available via nginx stub-status module # ################################## # Contact: # vincent.viallet@gmail.com # Zabbix requested parameter ZBX_REQ_DATA="$1" ZBX_REQ_DATA_URL="$2" # Nginx defaults NGINX_STATUS_DEFAULT_URL="127.0.0.1/nginx_status" #(这里写网站的域名) WGET_BIN="/usr/bin/wget" # # Error handling: # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) # - items need to be of type "float" (allow negative + float) # ERROR_NO_ACCESS_FILE="-0.9900" ERROR_NO_ACCESS="-0.9901" ERROR_WRONG_PARAM="-0.9902" ERROR_DATA="-0.9903" # either can not connect / bad host / bad port # Handle host and port if non-default if [ ! -z "$ZBX_REQ_DATA_URL" ]; then URL="$ZBX_REQ_DATA_URL" else URL="$NGINX_STATUS_DEFAULT_URL" fi # save the nginx stats in a variable for future parsing NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null) # error during retrieve if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then echo $ERROR_DATA exit 1 fi # # Extract data from nginx stats # case $ZBX_REQ_DATA in active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';; accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';; handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';; handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';; reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';; writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';; waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';; *) echo $ERROR_WRONG_PARAM; exit 1;; esac exit 0 chmod +x /usr/local/zabbix/share/scripts/nginx-check_performance.sh chown zabbix:zabbix /usr/local/zabbix/share/scripts/nginx-check_performance.sh vim /usr/local/zabbix/etc/zabbix_agentd.conf #找到 #UserParameter= ,删除注释,修改为:nginx[*],/usr/local/zabbix/share/scripts/nginx-check_performance.sh "$1" /etc/init.d/zabbix_agentd start #防火墙需允许10050端口

原文地址 : https://www.xj123.info/7145.html

本站遵循 : 署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5)

版权声明 : 原创文章转载时,请务必以超链接形式标明文章原始出处

Tags: nginx , zabbix
  • 上一篇:ThinkPad X220 终极改造超窄边框夏普IPS高分屏
  • 下一篇:Zabbix 3.2 agentd使用自带模板监控MySQL性能
0条评论

暂时没有评论!

发表评论 点击取消评论.

*必填

*必填

  • 文章归档
  • 子网计算
  • 我的共享
  • 锻炼计划
  • 给我留言
  • 关于老谢
2025 年 6 月
一 二 三 四 五 六 日
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« 5 月    

最新文章

  • 认知,是否是一座大山?当架构决策变成配置清单比价
  • 重装博客服务器环境
  • 特斯拉24款标续 Model Y 2万公里使用体验
  • 接盘的傻子
  • 小牛us电瓶指示灯闪三次不上电
  • 一次还不错的小米售后体验
  • 装台1600元办公主机
  • 2021好久没更新博客
  • Zabbix监控oxidized备份状态
  • Zabbix 5.0 LTS版本MySQL表分区及编译安装随记

最新评论

  • zwwooooo:类似以前做网站开发时,一开始有自...
  • 老陳网志:有点高端,像我们整点nas玩玩就够...
  • springwood:自从 CentOS 不维护之后,我换 U...
  • 大D:难都搞下来了,那就更得YM了
  • 大D:只能是YM了,谢总牛啊
  • 灰常记忆:经济不好 今年我也换了机器 一...
  • 大峰:这是海外服务器嘛?速度挺快的。
  • 大D:只能单走一个6了哈哈哈
  • zwwooooo:买特斯拉和买iPhone的人群其实相似...
  • 平安家属子痕:一直坚持油车,看你写的心里有...

日志存档

  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2024 年 9 月
  • 2024 年 5 月
  • 2024 年 1 月
  • 2023 年 4 月
  • 2021 年 10 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2020 年 11 月
  • 2020 年 9 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 10 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 3 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 1 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月
  • 2017 年 2 月
  • 2017 年 1 月
  • 2016 年 12 月
  • 2016 年 11 月
  • 2016 年 10 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 4 月
  • 2016 年 2 月
  • 2016 年 1 月
  • 2015 年 12 月
  • 2015 年 10 月
  • 2015 年 9 月
  • 2015 年 7 月
  • 2015 年 5 月
  • 2015 年 4 月
  • 2015 年 3 月
  • 2015 年 2 月
  • 2015 年 1 月
  • 2014 年 12 月
  • 2014 年 10 月
  • 2014 年 9 月
  • 2014 年 8 月
  • 2014 年 7 月
  • 2014 年 6 月
  • 2014 年 5 月
  • 2014 年 4 月
  • 2014 年 3 月
  • 2014 年 2 月
  • 2014 年 1 月
  • 2013 年 12 月
  • 2013 年 11 月
  • 2013 年 10 月
  • 2013 年 9 月
  • 2013 年 8 月
  • 2013 年 7 月
  • 2013 年 6 月
  • 2013 年 5 月
  • 2013 年 4 月
  • 2013 年 3 月
  • 2013 年 2 月
  • 2013 年 1 月
  • 2012 年 12 月
  • 2012 年 11 月
  • 2012 年 9 月
  • 2012 年 8 月
  • 2012 年 7 月
  • 2012 年 6 月
  • 2012 年 5 月
  • 2012 年 4 月
  • 2012 年 3 月
  • 2012 年 2 月
  • 2012 年 1 月
  • 2011 年 12 月
  • 2011 年 11 月
  • 2011 年 10 月
  • 2011 年 9 月
  • 2011 年 8 月
  • 2011 年 7 月
  • 2011 年 6 月
  • 2011 年 5 月
  • 2011 年 4 月
  • 2011 年 3 月
  • 2011 年 2 月
  • 2011 年 1 月
  • 2010 年 12 月
  • 2010 年 11 月
  • 2010 年 10 月
  • 2010 年 9 月
  • 2010 年 8 月
  • 2010 年 7 月

W3C

  • XHTML 1.0 Transitional
  • CSS level 3
  • Google+
Copyright © 2010-2025 老谢博客 All rights reserved.
Gzipped 76.5% | Optimized loading 43 queries in 1.185 seconds | Memory 38.95 MB | 尼玛的备案
Powered by WordPress. | Hosted By LAOXUEHOST | Theme by WordPress主题巴士 | 站点地图 | SiteMap | uptime查询