- 启用php-fpm状态功能
[root@node1:~]# vim /usr/local/php-7.0.12_fpm/etc/php-fpm.conf
pm.status_path = /status
[root@node1:~]# cat /usr/local/php-7.0.12_fpm/etc/php-fpm.conf |grep status_path
pm.status_path = /status
默认情况下为/status,当然也可以改成其他的,例如/chinasoft_status等等。
- nginx配置
在默认主机里面加上location或者你希望能访问到的主机里面。
使用socket的方式进行通讯(推荐)
server {
listen 80 default_server;
server_name 10.11.0.210;
location ~ ^/(status|ping)fastcgi_script_name;
}
}
对应php-fpm.conf配置
listen = /tmp/php-cgi.sock
使用fastcgi的方式进行通讯
server {
listen 80 default_server;
server_name 10.11.0.210;
location ~ ^/(status|ping)fastcgi_script_name;
}
}
对应php-fpm.conf配置
listen = 127.0.0.1:9000
- 重启nginx/php-fpm
请依照你的环境重启你的nginx和php-fpm
service nginx restart
service php-fpm restart
启动php-7.0.12_fpm报错
[root@node1:/usr/local/tengine-2.2.0/conf]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm /etc/init.d/php-fpm: line 82: kill: (9316) - No such process
................................... failed. Use force-quit
Starting php-fpm /usr/local/php/sbin/php-fpm: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory
failed
解决办法:
[root@node1:/usr/local/tengine-2.2.0/conf]# yum install -y libpng
- 打开status页面
[root@node1:/usr/local/php/etc]# curl http://10.11.0.210/status
pool: www
process manager: dynamic
start time: 13/Jun/2018:10:17:39 +0800
start since: 482
accepted conn: 2
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 63
active processes: 1
total processes: 64
max active processes: 1
max children reached: 0
slow requests: 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,缓慢请求的数量
- php-fpm其他参数
php-fpm状态页比较个性化的一个地方是它可以带参数,可以带参数json、xml、html并且前面三个参数可以分别和full做一个组合。
json
[root@node1:/usr/local/php/etc]# curl http://10.11.0.210/status?json
{"pool":"www","process manager":"dynamic","start time":1528856259,"start since":566,"accepted conn":3,"listen queue":0,"max listen queue":0,"listen queue len":0,"idle processes":63,"active processes":1,"total processes":64,"max active processes":1,"max children reached":0,"slow requests":0}
xml
curl http://127.0.0.1/status?xml
html
curl http://127.0.0.1/status?html
full
curl http://127.0.0.1/status?full
pool: www
process manager: dynamic
start time: 13/Jun/2018:10:39:54 +0800
start since: 43
accepted conn: 46
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 15
active processes: 1
total processes: 16
max active processes: 1
max children reached: 0
slow requests: 0
pid: 5262
state: Idle
start time: 13/Jun/2018:10:39:54 +0800
start since: 43
requests: 3
request duration: 203
request method: GET
request URI: /status
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
pid: 5263
state: Idle
start time: 13/Jun/2018:10:39:54 +0800
start since: 43
requests: 3
request duration: 130
request method: GET
request URI: /status
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
pid: 5264
state: Idle
start time: 13/Jun/2018:10:39:54 +0800
start since: 43
requests: 3
request duration: 129
request method: GET
request URI: /status
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
pid: 5265
state: Idle
start time: 13/Jun/2018:10:39:54 +0800
start since: 43
requests: 3
request duration: 154
request method: GET
request URI: /status
content length: 0
user: -
script: -
last request cpu: 0.00
last request memory: 2097152
......
6.5 full详解
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的监控模板
template php-fpm
1.添加监控脚本
vim /usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh
!/bin/bash
listenqueue(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "listen queue:"|grep -vE "len|max"|awk '{print$3}'
}
listenqueuelen(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "listen queue len" |awk '{print$4}'
}
idle(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "idle processes" |awk '{print3}'|grep -v "process"
}
total(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "total processes" |awk '{print$3}'
}
mactive(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "max active processes:" |awk '{print$4}'
}
since(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "start since: " |awk '{print$3}'
}
conn(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "accepted conn" |awk '{print$3}'
}
reached(){
curl -m 10 -s http://127.0.0.1:80/status?auto |grep "max children reached" |awk '{print3}'
}
$1
给脚本添加执行权限
chmod +x /usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh
2.增加配置文件
[root@node1:/usr/local/php/etc]# vim /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/php-fpm_status.conf
UserParameter=idle.processe,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh idle
UserParameter=total.processes,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh total
UserParameter=active.processes,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh active
UserParameter=max.active.processes,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh mactive
UserParameter=listen.queue.len,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh listenqueuelen
UserParameter=listen.queue,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh listenqueue
UserParameter=start.since,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh since
UserParameter=accepted.conn,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh conn
UserParameter=max.children.reached,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh reached
UserParameter=slow.requests,/usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh requests
3.重启客户端,并测试
[root@node1:~]# /usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh idle
15
[root@node1:~]# /usr/local/zabbix_agents_3.2.0/scripts/php-fpm_status.sh total
16
服务端测试
[root@node5 ~]# zabbix_get -s 10.11.0.210 -p 10050 -k "active.processes"
1
[root@node5 ~]# zabbix_get -s 10.11.0.210 -p 10050 -k "slow.requests"
0
[root@node5 ~]# zabbix_get -s 10.11.0.210 -p 10050 -k "total.processes"
16
zabbix监控php-fpm模板
Template php-fpm
作者:郑子明
来源:CSDN
原文:https://blog.csdn.net/reblue520/article/details/80891694
版权声明:本文为博主原创文章,转载请附上博文链接!