通过启用php-fpm的status页面,使用zabbix来获取各数据参数以达到监控php-fpm性能状态
php-fpm配置
配置文件php-fpm.confpm.status_path = /fpmstatus
ping.path = /fpmping
ping.response = pong
nginx配置
在配置的server内添加locationlocation ~ ^/(fpmstatus|fpmping) {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
access_log off;
allow 127.0.0.1;
deny all;
}
php-fpm status的含义字段含义poolphp-fpm pool的名称,大多数情况下为www
process manager进程管理方式,现今大多都为dynamic,不要使用static
start time启动时间
start since运行时长,单位秒
accepted connpool接收到的请求数
listen queue请求等待的连接数,如果不为0,需要增加php-fpm进程数
max listen queue从启动到现在处于等待连接的最大数量
listen queue lensocket等待队列长度
idle processes空闲进程数
active processes活跃进程数
total processess进程总数
max active process从php-fpm启动到现在最大的活跃进程数
max children reached当pm试图启动更多的children进程时,却达到了进程数的限制,达到一次记录一次,如果不为0,需要增加php-fpm pool进程的最大数
slow requests当启用了php-fpm slow-log功能时,如果出现php-fpm慢请求这个计数器会增加,一般不当的Mysql查询会触发这个值
php-fpm状态页可以通过带参数实现个性化,可以带参数json、xml、html、full,并且前三个参数可分别和full组合,即:#单个参数访问,如:
curl http://localhost/fpmstatus
curl http://localhost/fpmstatus?json
curl http://localhost/fpmstatus?xml
curl http://localhost/fpmstatus?html
curl http://localhost/fpmstatus?full
#组合形式,如:
curl http://localhost/fpmstatus?html&full
full详解:pid – 进程PID,可以单独kill这个进程
state – 当前进程的状态 (Idle, Running, …)
start time – 进程启动的日期
start since – 当前进程运行时长
requests – 当前进程处理了多少个请求
request duration – 请求时长(单位微妙)
request method – 请求方法 (GET, POST, …)
request URI – 请求URI
content length – 请求内容长度 (仅用于 POST)
user – 用户 (PHP_AUTH_USER) (如果没设置为‘-’)
script – PHP脚本 (如果没设置为‘-’)
last request cpu – 最后一个请求CPU使用率。
last request memory - 最后一个请求使用的内存
监控fpm
zabbix agent客户端脚本
/etc/zabbix/script/phpfpm_status.sh#!/bin/bash
SERVER='127.0.0.1:80'
/usr/bin/curl -s "http://127.0.0.1/fpmstatus?xml" | grep "" | awk -F'>|
zabbix agent客户端配置
/etc/zabbix/zabbix_agentd.d/userparameter_phpfpm.conf#Monitor php-fpm status
UserParameter=phpfpm.status[*],/etc/zabbix/script/phpfpm_status.sh $1
zabbix web端配置