Maison > développement back-end > tutoriel php > phpfpm使用自带的status优化步骤

phpfpm使用自带的status优化步骤

WBOY
Libérer: 2016-07-29 09:14:48
original
1662 Les gens l'ont consulté

php-fpm和nginx一样内建了一个状态页,对于想了解php-fpm的状态以及监控php-fpm非常有帮助。为了后续的zabbix监控,我们需要先了解php-fpm状态页是怎么回事。

1. 启用php-fpm状态功能

<code><span># cat  /usr/local/php-5.5.10/etc/php-fpm.conf | grep status_path</span>
pm.status_path = /status</code>
Copier après la connexion

2. nginx配置

<code>server {
    listen  *:<span>80</span> default_server;
    server_name _;
    location ~ ^/(status|ping)$
    {
        <span><strong>include</strong></span> fastcgi_params;
        fastcgi_pass <span>127.0</span><span>.0</span><span>.1</span>:<span>9000</span>;
        fastcgi_param SCRIPT_FILENAME <span>$fastcgi_script_name</span>;
    }
}</code>
Copier après la connexion

3. 重启nginx/php-fpm

<code>service nginx restart
service php<span>-fpm</span> restart</code>
Copier après la connexion

4. 打开status页面

<code><span># curl http://www.ttlsa.com/status</span>
pool:                 www
process manager:      dynamic
start time:           <span>14</span>/May/<span>2014</span>:<span>22</span>:<span>40</span>:<span>15</span> +<span>0800</span>
start since:          <span>58508</span>
accepted conn:        <span>33</span>
listen queue:         <span>0</span>
max listen queue:     <span>8</span>
listen queue len:     <span>0</span>
idle processes:       <span>2</span>
active processes:     <span>1</span>
total processes:      <span>3</span>
max active processes: <span>5</span>
max children reached: <span>0</span>
slow requests:        <span>2091</span></code>
Copier après la connexion

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请求等待<strong>队列</strong>,如果这个值不为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状态页比较个性化的一个地方是它可以带参数,可以带参数jsonxmlhtml并且前面三个参数可以分别和full做一个组合。
  • 6.1 json
<code># curl http://<span>127.0</span><span>.0</span><span>.1</span>/status?json
{"<span>pool</span>":<span><span>"www"</span></span>,"<span>process manager</span>":<span><span>"dynamic"</span></span>,"<span>start time</span>":<span><span>1400078415</span></span>,"<span>start since</span>":<span><span>59624</span></span>,"<span>accepted conn</span>":<span><span>27</span></span>,"<span>listen queue</span>":<span><span>0</span></span>,"<span>max listen queue</span>":<span><span>8</span></span>,"<span>listen queue len</span>":<span><span>0</span></span>,"<span>idle processes</span>":<span><span>2</span></span>,"<span>active processes</span>":<span><span>1</span></span>,"<span>total processes</span>":<span><span>3</span></span>,"<span>max active processes</span>":<span><span>5</span></span>,"<span>max children reached</span>":<span><span>0</span></span>,"<span>slow requests</span>":<span><span>2145</span></span>}</code>
Copier après la connexion
  • 6.2 xml
<code># curl http://127.0.0.1/status?xml
<span><?xml version="1.0" ?></span><span>status</span>><span>pool</span>>www<span><span>pool</span>></span><span>process-manager</span>>dynamic<span><span>process-manager</span>></span><span>start-time</span>>1400078415<span><span>start-time</span>></span><span>start-since</span>>59640<span><span>start-since</span>></span><span>accepted-conn</span>>36<span><span>accepted-conn</span>></span><span>listen-queue</span>>0<span><span>listen-queue</span>></span><span>max-listen-queue</span>>8<span><span>max-listen-queue</span>></span><span>listen-queue-len</span>>0<span><span>listen-queue-len</span>></span><span>idle-processes</span>>2<span><span>idle-processes</span>></span><span>active-processes</span>>1<span><span>active-processes</span>></span><span>total-processes</span>>3<span><span>total-processes</span>></span><span>max-active-processes</span>>5<span><span>max-active-processes</span>></span><span>max-children-reached</span>>0<span><span>max-children-reached</span>></span><span>slow-requests</span>>2145<span><span>slow-requests</span>></span></code>
Copier après la connexion
  • 6.3 html
<code># curl http://127.0.0.1/status?html
<span><span>html</span><span>xmlns</span>=<span>"http://www.w3.org/1999/xhtml"</span><span>xml:lang</span>=<span>"en"</span><span>lang</span>=<span>"en"</span>></span><span>head</span>><span>title</span>>PHP-FPM Status Page<span><span>title</span>></span><span><span>head</span>></span><span>body</span>><span>table</span>><span>tr</span>><span>th</span>>pool<span><span>th</span>></span><span>td</span>>www<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>process manager<span><span>th</span>></span><span>td</span>>dynamic<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>start time<span><span>th</span>></span><span>td</span>>14/May/2014:22:40:15 +0800<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>start since<span><span>th</span>></span><span>td</span>>59662<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>accepted conn<span><span>th</span>></span><span>td</span>>8<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>listen queue<span><span>th</span>></span><span>td</span>>0<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>max listen queue<span><span>th</span>></span><span>td</span>>8<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>listen queue len<span><span>th</span>></span><span>td</span>>0<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>idle processes<span><span>th</span>></span><span>td</span>>2<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>active processes<span><span>th</span>></span><span>td</span>>1<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>total processes<span><span>th</span>></span><span>td</span>>3<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>max active processes<span><span>th</span>></span><span>td</span>>5<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>max children reached<span><span>th</span>></span><span>td</span>>0<span><span>td</span>></span><span><span>tr</span>></span><span>tr</span>><span>th</span>>slow requests<span><span>th</span>></span><span>td</span>>2147<span><span>td</span>></span><span><span>tr</span>></span><span><span>table</span>></span><span><span>body</span>></span><span><span>html</span>></span></code>
Copier après la connexion
  • 6.4 full
<code># curl http://127.0.0.1/status?full
pool:                 www
process manager:      dynamic
start time:           14/May/2014:22:40:15 +0800
start since:          59695
accepted conn:        1
listen queue:         0
max listen queue:     8
listen queue len:     0
idle processes:       2
active processes:     1
total processes:      3
max active processes: 5
max children reached: 0
slow requests:        2148

************************
pid:                  29050
state:                Idle
start time:           15/May/2014:15:09:32 +0800
start since:          338
requests:             62
request duration:     1025585
request method:       GET
request URI:          /index.php
content length:       0
user:                 -
script:               /data/site/www.ttlsa.com/index.php
last request cpu:     45.83
last request memory:  24903680
.....省略几个PID....</code>
Copier après la connexion
  • 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 - 上一个请求使用的内存

7. 完成

php-fpm状态页非常使用,使用zabbix或者nagios监控可以考虑使用xml或者默认方式。用web的话,推荐使用html,表格会比较清晰。

以上就介绍了phpfpm使用自带的status优化步骤,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal