zabbix监控php-fpm性能状态

1. 启用php-fpm状态功能

# cat  /usr/local/php/etc/php-fpm.conf | grep status_path       
pm.status_path = /status

2. nginx配置

location ~ ^/(status|ping)$
    {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    }

3. 重启nginx/php-fpm

# service nginx restart
# service php-fpm restart

4. 打开status页面

# curl http://127.0.0.1/status    
pool:                 www
process manager:      dynamic
start time:           04/Feb/2016:17:22:03 +0800
start since:          923888
accepted conn:        202606
listen queue:         0
max listen queue:     1
listen queue len:     32768
idle processes:       5
active processes:     1
total processes:      6
max active processes: 6
max children reached: 0
slow requests:        0

5. 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,缓慢请求的数量

6. php-fpm其他参数

php-fpm状态页比较个性化的一个地方是它可以带参数,可以带参数json、xml、html并且前面三个参数可以分别和full做一个组合。

6.1 json

# curl http://127.0.0.1/status?json
{"pool":"www","process manager":"dynamic","start time":1454577723,"start since":924013,"accepted conn":202636,"listen queue":0,"max listen queue":1,"listen queue len":32768,"idle processes":5,"active processes":1,"total processes":6,"max active processes":6,"max children reached":0,"slow requests":0}

6.2 xml

# curl http://127.0.0.1/status?xml
<?xml version="1.0" ?>
<status>
<pool>www</pool>
<process-manager>dynamic</process-manager>
<start-time>1454577723</start-time>
<start-since>923976</start-since>
<accepted-conn>202619</accepted-conn>
<listen-queue>0</listen-queue>
<max-listen-queue>1</max-listen-queue>
<listen-queue-len>32768</listen-queue-len>
<idle-processes>5</idle-processes>
<active-processes>1</active-processes>
<total-processes>6</total-processes>
<max-active-processes>6</max-active-processes>
<max-children-reached>0</max-children-reached>
<slow-requests>0</slow-requests>

6.3 html

# curl http://127.0.0.1/status?html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>PHP-FPM Status Page</title></head>
<body>
<table>
<tr><th>pool</th><td>www</td></tr>
<tr><th>process manager</th><td>dynamic</td></tr>
<tr><th>start time</th><td>04/Feb/2016:17:22:03 +0800</td></tr>
<tr><th>start since</th><td>924097</td></tr>
<tr><th>accepted conn</th><td>202649</td></tr>
<tr><th>listen queue</th><td>0</td></tr>
<tr><th>max listen queue</th><td>1</td></tr>
<tr><th>listen queue len</th><td>32768</td></tr>
<tr><th>idle processes</th><td>5</td></tr>
<tr><th>active processes</th><td>1</td></tr>
<tr><th>total processes</th><td>6</td></tr>
<tr><th>max active processes</th><td>6</td></tr>
<tr><th>max children reached</th><td>0</td></tr>
<tr><th>slow requests</th><td>0</td></tr>
</table>
</body></html>

6.4 full

# curl http://127.0.0.1/status?full
pool:                 www
process manager:      dynamic
start time:           04/Feb/2016:17:22:03 +0800
start since:          924257
accepted conn:        202692
listen queue:         0
max listen queue:     1
listen queue len:     32768
idle processes:       5
active processes:     1
total processes:      6
max active processes: 6
max children reached: 0
slow requests:        0

************************
pid:                  18703
state:                Idle
start time:           14/Feb/2016:11:32:55 +0800
start since:          81205
requests:             3060
request duration:     52445
request method:       GET
request URI:          /sesamestreet/elmo/index.php
content length:       0
user:                 -
script:               /www//sesamestreet/elmo/index.php
last request cpu:     38.14
last request memory:  3670016

************************
pid:                  18396
state:                Idle
start time:           14/Feb/2016:11:32:01 +0800
start since:          81259
requests:             3061
request duration:     155
request method:       GET
request URI:          /index.php
content length:       0
user:                 -
script:               /www//index.php
last request cpu:     0.00
last request memory:  262144

************************
pid:                  19326
state:                Idle
start time:           14/Feb/2016:11:34:51 +0800
start since:          81089
requests:             3057
request duration:     69
request method:       GET
request URI:          /status?xml
content length:       0
user:                 -
script:               /status
last request cpu:     0.00
last request memory:  262144

************************
pid:                  17667
state:                Idle
start time:           14/Feb/2016:11:29:55 +0800
start since:          81385
requests:             3066
request duration:     117
request method:       GET
request URI:          /index.php
content length:       0
user:                 -
script:               /www//index.php
last request cpu:     0.00
last request memory:  262144

************************
pid:                  18954
state:                Idle
start time:           14/Feb/2016:11:33:50 +0800
start since:          81150
requests:             3060
request duration:     46680
request method:       GET
request URI:          /sesamestreet/elmo/index.php
content length:       0
user:                 -
script:               /www//sesamestreet/elmo/index.php
last request cpu:     64.27
last request memory:  3670016

************************
pid:                  17619
state:                Running
start time:           14/Feb/2016:11:29:52 +0800
start since:          81388
requests:             3068
request duration:     95
request method:       GET
request URI:          /status?full
content length:       0
user:                 -
script:               /status
last request cpu:     0.00
last request memory:  0

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 - 上一个请求使用的内存

zabbix客户端配置

增加自定义key

# cat zabbix_agentd.conf | grep 'php-fpm'
#php-fpm
UserParameter=php-fpm.status[*],/usr/bin/curl -s "http://127.0.0.1/status?xml" | grep "<$1>" | awk -F'>|<' '{ print $$3}'

重启zabbix客户端

/etc/init.d/zabbix_agentd restart

zabbix管理后台配置

导入php-fpm模板

进入后台->configuration->templates->import(右侧)->选择php模板->最后点击import。至此php-fpm模板已经导入到zabbix中

 

posted @ 2016-02-26 15:40  love19791125  阅读(722)  评论(0编辑  收藏  举报