最新消息:其实接手服务器,最最最重要的还是要看下数据库、文件备份情况!!!非常重要!!!

开启php-fpm状态页及pm.status_path状态详解

application shang 4710浏览 0评论

说明:
php-fpm和nginx一样,内建了个状态页,可以通过该状态页了解监控php-fpm的状态

具体:
1. php-fpm.conf开用php-fpm状态功能

# grep pm.status_path /usr/local/php/etc/php-fpm.conf
pm.status_path = /phpfpm_status

默认情况下为/status,当然也可以改成/phpfpm_status等,我这里是改成/phpfpm_status啦

2. nginx配置
在默认主机里面加上location或者你希望能访问到的主机里面。

server {
        listen 80;
        server_name 127.0.0.1;
        location /nginx_status {
                stub_status on;
                access_log off;
        }
        location /phpfpm_status {
                fastcgi_pass  127.0.0.1:9000;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        }
}

 
3. 重启nginx、php-fpm使配置生效

# /etc/init.d/nginx restart
# /etc/init.d/php-fpm restart

 
4. 打开status页面

# curl http://127.0.0.1/phpfpm_status
pool:                 php_pool
process manager:      static
start time:           07/May/2015:09:29:44 +0800
start since:          4584829
accepted conn:        1697
listen queue:         0
max listen queue:     84
listen queue len:     0
idle processes:       49
active processes:     1
total processes:      50
max active processes: 50
max children reached: 0
slow requests:        29333

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

 
附录:
附录1:php-fpm状态页可以通过带参数实现个性化,可以带参数json、xml、html并且前面三个参数可以分别和full做一个组合。
1.1 json格式

# curl http://127.0.0.1/phpfpm_status?json
{"pool":"php_pool","process manager":"static","start time":1430962184,"start since":4584963,"accepted conn":4515,"listen queue":0,"max listen queue":84,"listen queue len":0,"idle processes":49,"active processes":1,"total processes":50,"max active processes":50,"max children reached":0,"slow requests":29333}

 
1.2 xml格式

# curl http://127.0.0.1/phpfpm_status?xml
<?xml version="1.0" ?>
<status>
<pool>php_pool</pool>
<process-manager>static</process-manager>
<start-time>1430962184</start-time>
<start-since>4584995</start-since>
<accepted-conn>5058</accepted-conn>
<listen-queue>0</listen-queue>
<max-listen-queue>84</max-listen-queue>
<listen-queue-len>0</listen-queue-len>
<idle-processes>49</idle-processes>
<active-processes>1</active-processes>
<total-processes>50</total-processes>
<max-active-processes>50</max-active-processes>
<max-children-reached>0</max-children-reached>
<slow-requests>29333</slow-requests>
</status>

 
1.3 html格式

# curl http://127.0.0.1/phpfpm_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>php_pool</td></tr>
<tr><th>process manager</th><td>static</td></tr>
<tr><th>start time</th><td>07/May/2015:09:29:44 +0800</td></tr>
<tr><th>start since</th><td>4585046</td></tr>
<tr><th>accepted conn</th><td>6009</td></tr>
<tr><th>listen queue</th><td>0</td></tr>
<tr><th>max listen queue</th><td>84</td></tr>
<tr><th>listen queue len</th><td>0</td></tr>
<tr><th>idle processes</th><td>49</td></tr>
<tr><th>active processes</th><td>1</td></tr>
<tr><th>total processes</th><td>50</td></tr>
<tr><th>max active processes</th><td>50</td></tr>
<tr><th>max children reached</th><td>0</td></tr>
<tr><th>slow requests</th><td>29333</td></tr>
</table>
</body></html>

 
1.4 full格式

# curl http://127.0.0.1/phpfpm_status?full

pid:                  22269
state:                Idle
start time:           29/Jun/2015:10:45:16 +0800
start since:          1339
requests:             537
request duration:     9053
request method:       POST
request URI:          /test.php
content length:       114
user:                 -
script:               /data/www/coolnull/public/test1.php
last request cpu:     0.00
last request memory:  786432

************************
pid:                  21485
state:                Idle
start time:           29/Jun/2015:10:42:07 +0800
start since:          1528
requests:             604
request duration:     6687
request method:       POST
request URI:          /test2.php
content length:       118
user:                 -
script:               /data/www/coolnull/public/test2.php
last request cpu:     0.00
last request memory:  786432

************************

以下省略多个PID

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

 
附录2:用zabbix、nagios监控php-fpm状态页时可能用xml或默认方式。web时则推荐使用html,表格比较清晰

附录3:phpfpm命令英文详解
pool – the name of the pool that is listening on the connected socket, as defined in the php-fpm config.
process manager – the method used by the process manager to control the number of child processes – either ondemand, dynamic or static – set on a per pool basis (in the php-fpm config) by the pm parameter.
start time – the date, time, and UTC offset corresponding to when the PHP-FPM server was started.
start since – the number of seconds that have elapsed since the PHP-FPM server was started (i.e. uptime).
accepted conn – the number of incoming requests that the PHP-FPM server has accepted; when a connection is accepted it is removed from the listen queue (displayed in real time).
listen queue – the current number of connections that have been initiated, but not yet accepted. If this value is non-zero it typically means that all the available server processes are currently busy, and there are no processes available to serve the next request. Raising pm.max_children (provided the server can handle it) should help keep this number low. This property follows from the fact that PHP-FPM listens via a socket (TCP or file based), and thus inherits some of the characteristics of sockets.
max listen queue – the maximum value the listen queue has reached since the server was started.
listen queue len – the upper limit on the number of connections that will be queued Once this limit is reached, subsequent connections will either be refused, or ignored. This value is set by the php-fpm per pool configuration option ‘listen.backlog’, which defaults to -1 (unlimited). However, this value is also limited by the system (sysctl) value ‘net.core.somaxconn’, which defaults to 128 on many Linux systems.
idle processes – the number of servers in the ‘waiting to process’ state (i.e. not currently serving a page). This value should fall between the pm.min_spare_servers and pm.max_spare_servers values when the process manager is dynamic. (updated once per second)
active processes – the number of servers current processing a page – the minimum is 1 (so even on a fully idle server, the result will be not read 0). (updated once per second)
total processes – the total number of server processes currently running; the sum of idle processes + active processes. If the process manager is static, this number will match pm.max_children. (updated once per second)
max active processes – the highest value that ‘active processes’ has reached since the php-fpm server started. This value should not exceed pm.max_children.
max children reached – the number of times that pm.max_children has been reached since the php-fpm server started (only applicable if the process manager is ondemand or dynamic)

转载请注明:酷喃|coolnull| » 开启php-fpm状态页及pm.status_path状态详解

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址