zabbix自定义key监控nginx和fpm(网站并发数)

一、 nginx编译参数

监控nginx,主要讲解监控并发数

--prefix=/usr/local/nginx --with-http_stub_status_module

zabbix编译参数的查看:

/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.
built by gcc 4.4. (Red Hat 4.4.-) (GCC)
built with OpenSSL 1.0.1e-fips Feb
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module

二、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

三、测试下看看能不能获取nginx状态

curl 127.0.0.1/status

四、写脚本获取nginx的状态

监控脚本(/usr/local/zabbix/check_nginx.sh):
#!/bin/sh
#nginx status
#Active connections:
#server accepts handled requests #Reading: Writing: Waiting:
while getopts "o:" opt
do
case $opt in
o ) option=$OPTARG;;
? )
echo 'parameter is wrong!'
exit ;;
esac
done
if [ ! "${option}" ];then
echo "parameter is null"
exit
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

五、zabbix配置(/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf)

UserParameter=nginx.status[*],sh /usr/local/zabbix/check_nginx.sh -o $
重启zabbix agentd(pkill zabbix_agentd; sleep ; /usr/local/zabbix/sbin/zabbix_agentd )

六、zabbix网页配置

nginx.status[accepts] 整形(每秒差值)

监控fpm,主要讲解监控动态并发数

/usr/local/php/etc/php-fpm.conf fpm配置新增

pm.status_path = /php_fpm_status
fpm需要重启。

nginx配置新增

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

测试看看能不能获取到fpm的状态

curl 127.0.0.1/php_fpm_status
pool: www
process manager: static
start time: /Jun/::: +
start since:
accepted conn:
listen queue:
max listen queue:
listen queue len:
idle processes:
active processes:
total processes:
max active processes:
max children reached:
slow requests:

写脚本获取fpm的状态

监控脚本(/usr/local/zabbix/check_fpm.sh):
#!/bin/sh
# fpm status
#curl 127.0.0.1/php_fpm_status
#pool: www
#process manager: static
#start time: /Jun/::: +
#start since:
#accepted conn:
#listen queue:
#max listen queue:
#listen queue len:
#idle processes:
#active processes:
#total processes:
#max active processes:
#max children reached:
#slow requests:
while getopts "o:" opt
do
case $opt in
o ) option=$OPTARG;;
? )
echo 'parameter is wrong!'
exit ;;
esac
done
if [ ! "${option}" ];then
echo "parameter is null"
exit
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

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

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

zabbix网页配置

fpm.status[conn]
上一篇:鱼搜_鱼搜官网_鱼搜搜索_http://www.7yusou.com


下一篇:VMWare虚拟机启动报错物理内存不足