实例一、监控PHP服务
环境:centos7.6 php7.2 nginx1.12
服务器:test14
- 修改php-fpm和nginx的配置文件,以便查看php的汇总信息和详细信息,如下:
1\ 修改php-fpm配置文件
vim /etc/php-fpm.d/www.conf
把
;pm.status_path = /status
更改为:
pm.status_path = /phpstatus #去掉了前面的;注释符,并更名为phpstatus(这个可自定义的)
2\ 修改nginx配置文件
server {
listen 80 default_server;
server_name _;
index index.php index.html
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location = /phpstatus {
allow 127.0.0.1;
#deny all;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
}
}
- 重启php-fpm和nginx
nginx -s reload
systemctl restart php-fpm
- 统计一下php的汇总信息
[root@test14 ~]# curl 127.0.0.1/phpstatus
pool: www
process manager: dynamic
start time: 22/Aug/2019:10:36:50 +0800
start since: 793
accepted conn: 3
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 4
active processes: 1
total processes: 5
max active processes: 1
max children reached: 0
slow requests: 0
- zabbix客户端添加php监控项
[root@test14 ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_php_fpm.conf
# PHP-FPM STATUS
UserParameter=php_fpm.status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/scripts/check_php_fpm.sh '$1'
- zabbix客户端添加监控脚本
[root@test14 ~]# cat /etc/zabbix/zabbix_agentd.d/scripts/check_php_fpm.sh
#!/bin/bash -
cache_file="/tmp/php_fpm_stats.txt"
if [ -e $cache_file ]; then
TIMEFLM=`stat -c %Y $cache_file`
TIMENOW=`date +%s`
if [ `expr $TIMENOW - $TIMEFLM` -gt 60 ]; then
rm -f $cache_file
curl --connect-timeout 1 -m 1 localhost/phpstatus 2> /dev/null > $cache_file
fi
else
curl --connect-timeout 1 -m 1 localhost/phpstatus 2> /dev/null > $cache_file
fi
case $1 in
'pool')
awk -F '[: ]+' '/pool/{print $NF}' $cache_file
;;
'accepted_conn')
curl --connect-timeout 1 -m 1 localhost/phpstatus 2> /dev/null | awk -F '[: ]+' '/accepted conn/{print $NF}'
;;
'listen_queue')
awk -F '[: ]+' '/listen queue/{print $NF}' $cache_file
;;
'max_listen_queue')
awk -F '[: ]+' '/max listen queue/{print $NF}' $cache_file
;;
'listen_queue_len')
awk -F '[: ]+' '/listen queue len/{print $NF}' $cache_file
;;
'idle_processes')
awk -F '[: ]+' '/idle processes/{print $NF}' $cache_file
;;
'active_processes')
awk -F '[: ]+' '/^active processes/{print $NF}' $cache_file
;;
'total_processes')
awk -F '[: ]+' '/total processes/{print $NF}' $cache_file
;;
'max_active_processes')
awk -F '[: ]+' '/^max active processes/{print $NF}' $cache_file
;;
'max_children_reached')
awk -F '[: ]+' '/max children reached/{print $NF}' $cache_file
;;
*)
exit 1
;;
esac
- 重启zabbix客户端
root@test14 ~]# systemctl restart zabbix-agent
zabbix的web页面上操作:
添加模板名为PHP_FPM的模板
在模板内添加名为PHP_FPM的应用集
按需求添加php的监控项,我这里添加了6个监控项,分别是:
1、active_processes
2、idle_processes
3、total_processes
4、max_active_processes
5、accepted_conn
6、pool
下面以创建active_processes的监控项为例,其它监控项参考创建:添加触发器
及添加图形
及
注:zabbix监控其它服务可以参照上面的方式上来配置
文档更新时间: 2019-08-22 14:32 作者:子木