前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Zabbix监控Nginx和fpm(网站并发数)自定义key

Zabbix监控Nginx和fpm(网站并发数)自定义key

作者头像
星哥玩云
发布2022-07-14 10:07:22
3380
发布2022-07-14 10:07:22
举报
文章被收录于专栏:开源部署开源部署

监控nginx,主要讲解监控并发数: 1: nginx编译参数: --prefix=/usr/local/nginx --with-http_stub_status_module

zabbix编译参数的查看: /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module

2: nginx配置新增

location /status { allow 127.0.0.1; deny all; stub_status on; access_log off; } 重启nginx: /usr/local/nginx/sbin/nginx -t /usr/local/nginx/sbin/nginx -s reload

3: 测试下看看能不能获取nginx状态 curl 127.0.0.1/status

4: 写脚本获取nginx的状态 监控脚本(/usr/local/zabbix/check_nginx.sh):

#!/bin/sh #20170603 nginx status #Active connections: 1 #server accepts handled requests #1035268066 1035268066 1035136592 #Reading: 0 Writing: 1 Waiting: 0 while getopts "o:" opt do case $opt in o ) option=$OPTARG;; ? ) echo 'parameter is wrong!' exit 1;; esac done if [ ! "${option}" ];then echo "parameter is null" exit 1 fi if [[ ${option} == "active" ]];then curl -s 127.0.0.1/status |grep '^Active connections' |awk '{print $NF}' elif [[ ${option} == "accepts" ]];then curl -s 127.0.0.1/status |awk 'NR==3'|awk '{print $1}' fi

5: zabbix配置(/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf): UserParameter=nginx.status[*],sh /usr/local/zabbix/check_nginx.sh -o $1 重启zabbix agentd(pkill zabbix_agentd; sleep 3; /usr/local/zabbix/sbin/zabbix_agentd )

6: zabbix网页配置: nginx.status[accepts] ×××(每秒差值)

监控fpm,主要讲解监控动态并发数: 1: /usr/local/php/etc/php-fpm.conf fpm配置新增: pm.status_path = /php_fpm_status fpm需要重启。

2: nginx配置新增:

location /php_fpm_status { allow 127.0.0.1; deny all; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } nginx需要reload

3: 测试看看能不能获取到fpm的状态 curl 127.0.0.1/php_fpm_status pool: www process manager: static start time: 02/Jun/2017:17:45:05 +0800 start since: 58677 accepted conn: 10753843 listen queue: 0 max listen queue: 0 listen queue len: 0 idle processes: 249 active processes: 1 total processes: 250 max active processes: 251 max children reached: 0 slow requests: 426

4: 写脚本获取fpm的状态 监控脚本(/usr/local/zabbix/check_fpm.sh):

#!/bin/sh #20170603 fpm status #curl 127.0.0.1/php_fpm_status #pool: www #process manager: static #start time: 02/Jun/2017:17:45:05 +0800 #start since: 59022 #accepted conn: 10768453 #listen queue: 0 #max listen queue: 0 #listen queue len: 0 #idle processes: 249 #active processes: 1 #total processes: 250 #max active processes: 251 #max children reached: 0 #slow requests: 426 while getopts "o:" opt do case $opt in o ) option=$OPTARG;; ? ) echo 'parameter is wrong!' exit 1;; esac done if [ ! "${option}" ];then echo "parameter is null" exit 1 fi if [[ ${option} == "conn" ]];then curl -s 127.0.0.1/php_fpm_status |grep '^accepted conn'|awk '{print $NF}' elif [[ ${option} == "idle" ]];then curl -s 127.0.0.1/php_fpm_status |grep '^idle processes'|awk '{print $NF}' elif [[ ${option} == "active" ]];then curl -s 127.0.0.1/php_fpm_status |grep '^active processes'|awk '{print $NF}' fi

5: zabbix配置(vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/fpm.conf):

UserParameter=fpm.status[*],sh /usr/local/zabbix/check_fpm.sh -o $1 重启zabbix agent。pkill zabbix_agentd; sleep 3; /usr/local/zabbix/sbin/zabbix_agentd

6: zabbix网页配置: fpm.status[conn]

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档