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

栏目: 服务器 · Nginx · 发布时间: 6年前

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

监控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]

更多Zabbix相关教程集合: 

在Ubuntu 16.04服务器上安装Zabbix 3.2  https://www.linuxidc.com/Linux/2017-07/145519.htm

CentOS 7 LNMP环境搭建Zabbix3.0  https://www.linuxidc.com/Linux/2017-02/140134.htm

Ubuntu 16.04安装部署监控系统Zabbix2.4  https://www.linuxidc.com/Linux/2017-03/141436.htm

Zabbix监控安装部署及警报配置  https://www.linuxidc.com/Linux/2017-03/141611.htm

Zabbix触发器表达式详解 https://www.linuxidc.com/Linux/2017-03/141921.htm

Ubuntu 16.04下安装部署Zabbix3.0  https://www.linuxidc.com/Linux/2017-02/140395.htm

CentOS 7 下 Zabbix 3.0安装详解 https://www.linuxidc.com/Linux/2017-03/141716.htm

Zabbix 3.2.6 通过Orabbix监控Oracle数据库  https://www.linuxidc.com/Linux/2017-10/147224.htm

Zabbix3.4添加Web监测功能 https://www.linuxidc.com/Linux/2018-06/152769.htm

Zabbix告警发送邮件时附带性能图 https://www.linuxidc.com/Linux/2018-05/152194.htm

Zabbix3.0编译升级过程记录 https://www.linuxidc.com/Linux/2018-05/152193.htm

Debian 9.2安装Zabbix 3.4.2 https://www.linuxidc.com/Linux/2018-03/151338.htm

ZABBIX 的详细介绍 请点这里

ZABBIX 的下载地址 请点这里

Linux公社的RSS地址: https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址: https://www.linuxidc.com/Linux/2018-08/153630.htm


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

微创新

微创新

德鲁•博迪、雅各布•戈登堡 / 钟莉婷 / 中信出版社 / 2014-4-5 / 42.00

好产品不一定要颠覆,微小改进就能让用户尖叫! 引爆创新领域的全新方法论 互联网时代行之有效的5大创新策略 创业者、产品经理必读的创新行动指南 《怪诞行为学》作者 丹•艾瑞里 《影响力》作者 罗伯特•西奥迪尼 全球50位最具影响力的商业思想家之一丹尼尔•平克 周鸿祎、黎万强、罗振宇、牛文文、张鹏 联袂重磅推荐 为什么iPod可以在众多mp3产品中......一起来看看 《微创新》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具