- 启用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模板
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.2</version>
<date>2018-06-27T12:26:33Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template php-fpm</template>
<name>Template php-fpm</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<items>
<item>
<name>accepted conn</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>accepted.conn</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>k</units>
<delta>1</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>active processes</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>active.processes</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>php-fpm_idle_processes</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>idle.processe</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>listen queue</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>listen.queue</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>listen queue len</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>listen.queue.len</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>max active processes</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>max.active.processes</key>
<delay>30</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>max children reached</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>max.children.reached</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>1</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>2</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>slow requests</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>slow.requests</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>1</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>2</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>start since</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>start.since</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>1</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>2</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>total processes</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>total.processes</key>
<delay>60</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
<item>
<name>up</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>up</key>
<delay>30</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>php-fpm</name>
</application>
</applications>
<valuemap/>
<logtimefmt/>
</item>
</items>
<discovery_rules/>
<httptests/>
<macros>
<macro>
<macro>{$PHP_FPM_STATUS_URL}</macro>
<value>http://127.0.0.1:10061/php-fpm_status</value>
</macro>
</macros>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>{Template php-fpm:up.last()}=0</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>php-fpm was down</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>0</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger>
</triggers>
<graphs>
<graph>
<name>php-fpm_status</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>C800C8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template php-fpm</host>
<key>active.processes</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>0</drawtype>
<color>00C8C8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template php-fpm</host>
<key>listen.queue</key>
</item>
</graph_item>
<graph_item>
<sortorder>2</sortorder>
<drawtype>0</drawtype>
<color>C8C800</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template php-fpm</host>
<key>listen.queue.len</key>
</item>
</graph_item>
<graph_item>
<sortorder>3</sortorder>
<drawtype>0</drawtype>
<color>C8C8C8</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template php-fpm</host>
<key>max.active.processes</key>
</item>
</graph_item>
<graph_item>
<sortorder>4</sortorder>
<drawtype>0</drawtype>
<color>960000</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template php-fpm</host>
<key>idle.processe</key>
</item>
</graph_item>
<graph_item>
<sortorder>5</sortorder>
<drawtype>0</drawtype>
<color>000096</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template php-fpm</host>
<key>total.processes</key>
</item>
</graph_item>
</graph_items>
</graph>
</graphs>
</zabbix_export>
作者:郑子明
来源:CSDN
原文:https://blog.csdn.net/reblue520/article/details/80891694
版权声明:本文为博主原创文章,转载请附上博文链接!