在 Ubuntu 上监控 PHP-FPM 可以从 进程状态、性能、慢日志、系统资源、告警 等多个层面来做。下面给你一套可落地的监控方案,从简单到完整。
systemctl status php-fpm
# 或(Ubuntu 常见)
systemctl status php8.1-fpm
ps aux | grep php-fpm
这是最常用、最有效的监控方式。
编辑 pool 配置:
vim /etc/php/8.1/fpm/pool.d/www.conf
取消或添加:
pm.status_path = /status
location /status {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 可选:限制访问
allow 127.0.0.1;
deny all;
}
curl http://127.0.0.1/status
输出示例:
pool: www
process manager: dynamic
start time: 01/Jan/2026:10:00:00 +0800
start since: 3600
accepted conn: 12000
listen queue: 0
max listen queue: 2
active processes: 5
total processes: 10
✅ 可监控指标:
request_slowlog_timeout = 2s
slowlog = /var/log/php8.1-fpm.slow.log
tail -f /var/log/php8.1-fpm.slow.log
✅ 常用于:
htop
查看:
ss -x | grep php
php-fpm-exporter推荐:
https://github.com/hipages/php-fpm_exporter
- job_name: php-fpm
static_configs:
- targets: ["localhost:9253"]
可监控:
✅ 生产环境最推荐
tail -f /var/log/php8.1-fpm.log
常见错误:
server reached pm.max_childrentime outfailed to connect| 指标 | 说明 |
|---|---|
| active processes | 当前活跃进程 |
| listen queue | 等待处理的请求 |
| max listen queue | 历史最大队列 |
| accepted conn | 总请求数 |
| slow requests | 慢请求 |
| memory / cpu | 资源占用 |
listen queue > 10 ⚠️active processes = pm.max_children ⚠️systemctl status php8.1-fpm
curl http://127.0.0.1/status
tail -f /var/log/php8.1-fpm.log
tail -f /var/log/php8.1-fpm.slow.log
如果你愿意,我可以:
你现在是在 本地 / 云服务器 / 容器 环境?