php-fpm和nginx一样内建了一个状态页,对于想了解php-fpm的状态以及监控php-fpm非常有帮助。 为了后续的zabbix监控,我们需要先了解php-fpm状态页是怎么回事。
cat /usr/local/php-5.5.10/etc/php-fpm.conf | grep status_path pm.status_path = /status
或者 /etc/php-fpm.d/www.conf 默认注释 删除即可
默认情况下为/status,当然也可以改成其他的,例如/qxfell_status等等。
location ~ ^/(status|ping)$
{
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
重启Nginx和php-fpn 用crul查看获取状态
curl http://192.168.242.110/status
pool: www
process manager: dynamic
start time: 01/Apr/2017:00:58:44 +0800
start since: 1976
accepted conn: 516
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 7
active processes: 1
total processes: 8
max active processes: 6
max children reached: 0
php-fpm status详解
pool – fpm池子名称,大多数为www
process manager – 进程管理方式,值:static, dynamic or ondemand. dynamic
start time – 启动日期,如果reload了php-fpm,时间会更新
start since – 运行时长
accepted conn – 当前池子接受的请求数
listen queue – 请求等待队列,如果这个值不为0,那么要增加FPM的进程数量
max listen queue – 请求等待队列最高的数量
listen queue len – socket等待队列长度
idle processes – 空闲进程数量
active processes – 活跃进程数量
total processes – 总进程数量
max active processes – 最大的活跃进程数量(FPM启动开始算)
max children reached - 大道进程最大数量限制的次数,如果这个数量不为0,那说明你的最大进程数量太小了,请改大一点。
slow requests – 启用了php-fpm slow-log,缓慢请求的数量
vim /etc/zabbix/alertscripts
#!/bin/bash
listenqueue(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "listen queue:"|grep -vE "len|max"|awk '{print$3}'
}
listenqueuelen(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "listen queue len" |awk '{print$4}'
}
idle(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "idle processes" |awk '{print$3}'
}
active(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "active" |awk '{print$3}'|grep -v "process"
}
total(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "total processes" |awk '{print$3}'
}
mactive(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "max active processes:" |awk '{print$4}'
}
since(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "start since: " |awk '{print$3}'
}
conn(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "accepted conn" |awk '{print$3}'
}
reached(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "max children reached" |awk '{print$4}'
}
requests(){
wget --quiet -O - http://127.0.0.1:80/status?auto |grep "slow requests" |awk '{print$3}'
}
$1
#vim /etc/zabbix/zabbix_agentd.conf
UserParameter=idle.processe,/etc/zabbix/alertscripts/php-fpm_status.sh idle
UserParameter=total.processes,/etc/zabbix/alertscripts/php-fpm_status.sh total
UserParameter=active.processes,/etc/zabbix/alertscripts/php-fpm_status.sh active
UserParameter=max.active.processes,/etc/zabbix/alertscripts/php-fpm_status.sh mactive
UserParameter=listen.queue.len,/etc/zabbix/alertscripts/php-fpm_status.sh listenqueuelen
UserParameter=listen.queue,/etc/zabbix/alertscripts/php-fpm_status.sh listenqueue
UserParameter=start.since,/etc/zabbix/alertscripts/php-fpm_status.sh since
UserParameter=accepted.conn,/etc/zabbix/alertscripts/php-fpm_status.sh conn
UserParameter=max.children.reached,/etc/zabbix/alertscripts/php-fpm_status.sh reached
UserParameter=slow.requests,/etc/zabbix/alertscripts/php-fpm_status.sh requests