背景
phpfpm跟nginx一样有个status状态监控页。可能通过status状态监控页了解phpfpm的运行状态,如并发数,总进程数等。
启用php-fpm状态功能
# vim /usr/local/php/etc/php-fpm.conf | grep status_path pm.status_path = /fpm_status //这个要与nginx上的location上一致
nginx配置
在默认主机里面加上location或者你希望能访问到的主机里面。
server { listen 80; server_name 127.0.0.1; location /fpm_status { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
重启nginx,php-fpm
打开status页面
curl 127.0.0.1/fpm_status pool: www process manager: static start time: 13/Aug/2021:10:31:56 +0800 start since: 110254 accepted conn: 4 listen queue: 0 max listen queue: 0 listen queue len: 0 idle processes: 4 active processes: 1 total processes: 5 max active processes: 100 max children reached: 0 slow requests: 111
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,缓慢请求的数量
其他参数
php-fpm状态页比较个性化的一个地方是它可以带参数,可以带参数json、xml、html并且前面三个参数可以分别和full做一个组合。
例如json,其他只是格式不一样,不再一一展示
curl 127.0.0.1/fpm_status?json {"pool":"www","process manager":"static","start time":1630290716,"start since":110357,"accepted conn":100,"listen queue":0,"max listen queue":0,"listen queue len":0,"idle processes":82,"active processes":18,"total processes":100,"max active processes":100,"max children reached":0,"slow requests":111248}
重点介绍full
curl 127.0.0.1/fpm_status?full |more % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 53898 0 53898 0 0 29.9M 0 --:--:-- --:--:-- --:--:-- 51.4M pool: www process manager: static start time: 30/Aug/2021:10:31:56 +0800 start since: 110491 accepted conn: 111 listen queue: 0 max listen queue: 0 listen queue len: 0 idle processes: 76 active processes: 24 total processes: 100 max active processes: 100 max children reached: 0 slow requests: 111570 ************************ pid: 5655 state: Idle start time: 31/Aug/2021:16:47:17 +0800 start since: 1617 requests: 1709 request duration: 57695 request method: GET request URI: /index.php?s=/Test/test content length: 0 user: - script: /data/nginx/webroot/www/index.php last request cpu: 17.33 last request memory: 1835008
参数介绍:
pid – 进程PID,可以单独kill这个进程. You can use this PID to kill a long running process. state – 当前进程的状态 (Idle, Running, …) start time – 进程启动的日期 start since – 当前进程运行时长 requests – 当前进程处理了多少个请求 request duration – 请求时长(微妙) request method – 请求方法 (GET, POST, …) request URI – 请求URI content length – 请求内容长度 (仅用于 POST) user – 用户 (PHP_AUTH_USER) (or ‘-’ 如果没设置) script – PHP脚本 (or ‘-’ if not set) last request cpu – 最后一个请求CPU使用率。 last request memorythe – 上一个请求使用的内存
总结
php-fpm状态页很实用,使用zabbix或者nagios监控可以考虑使用xml或者默认方式。用web的话,推荐使用html,表格会比较清晰。
《本文》有 0 条评论