查看php-fpm的运行状态
前面的文章中有提到nginx开启http_stub_status_module模块,可以查看nginx的运行状态,输出示例为:
Active connections: 3
server accepts handled requests
17737 17737 49770
Reading: 0 Writing: 1 Waiting: 2
各项解释:
Active connections: 当前 Nginx 正处理的活动连接数.
server accepts handled requests: 总共处理了 17737 个连接, 成功创建 17737 次握手(证明中间没有失败的), 总共处理了 49770 个请求.
Reading: Nginx 读取到客户端的 Header 信息数.
Writing: Nginx 返回给客户端的 Header 信息数.
Waiting: 开启 keep-alive 的情况下, 这个值等于 Active – (Reading + Writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
当然,该nginx模块还可以配置官方介绍的nginx-rrd来实现图形化的状态监控,像php-fpm也可以配合zabbix来实现图形化监控。
下面介绍下如何查看php-fpm的运行状态:
1.在/usr/local/php/etc/php-fpm.d/www.conf 中开启status_path
1 |
pm.status_path = /fpm_status |
2.在nginx配置文件中添加 server虚拟主机:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@localhost conf.d]# cat php-fpm-status.conf server { listen 10001; server_name localhost; allow 127.0.0.1; deny all; #php-fpm状态 location ~ ^/(fpm_status)${ include /usr/local/nginx/conf/fastcgi_params; #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/dev/shm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } } |
3.平滑重启php-fpm和nginx
4.运行示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[root@localhost conf.d]# curl 127.0.0.1:10001/fpm_status pool: www —— fpm池子名称,即php运行的组 process manager: static ——进程管理方式,即php-fpm运行的方式,值有static, dynamic or ondemand. dynamic start time: 21/Apr/2016:10:38:19 +0800 ——启动日期,如果reload了php-fpm,时间会更新 start since: 22899017 ——运行时长 accepted conn: 55620341 ——当前池子接受的请求数 listen queue: 0 ——请求等待队列,如果这个值不为0,那么要增加FPM的进程数量 max listen queue: 246 ——请求等待队列最高的数量 listen queue len: 65535 ——socket等待队列长度 idle processes: 199 ——空闲进程数量 active processes: 1 ——活跃进程数量 total processes: 200 —— 总进程数量 max active processes: 200 ——最大的活跃进程数量(FPM启动开始算) max children reached: 0 ——进程最大数量限制的次数,如果这个数量不为0,那说明你的最大进程数量太小了,请改大一点。 slow requests: 0 ——启用时php-fpm slow-log的慢请求数 |
5.可通过带不同参数查看php-fpm status输出格式:
- http://www.foo.bar/status #默认纯文本
- http://www.foo.bar/status?json #json格式
- http://www.foo.bar/status?html #html格式
- http://www.foo.bar/status?xml #xml格式
- #full参数可查看进程详细信息
- http://www.foo.bar/status?full
- http://www.foo.bar/status?json&full
- http://www.foo.bar/status?html&full
- http://www.foo.bar/status?xml&full
附:php-fpm配置文件说明
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
; The URI to view the FPM status page. If this value is not set, no URI will be ; recognized as a status page. It shows the following informations: ; pool - the name of the pool; ; process manager - static, dynamic or ondemand; ; start time - the date and time FPM has started; ; start since - number of seconds since FPM has started; ; accepted conn - the number of request accepted by the pool; ; listen queue - the number of request in the queue of pending ; connections (see backlog in listen(2)); ; max listen queue - the maximum number of requests in the queue ; of pending connections since FPM has started; ; listen queue len - the size of the socket queue of pending connections; ; idle processes - the number of idle processes; ; active processes - the number of active processes; ; total processes - the number of idle + active processes; ; max active processes - the maximum number of active processes since FPM ; has started; ; max children reached - number of times, the process limit has been reached, ; when pm tries to start more children (works only for ; pm 'dynamic' and 'ondemand'); ; Value are updated in real time. ; Example output: ; pool: www ; process manager: static ; start time: 01/Jul/2011:17:53:49 +0200 ; start since: 62636 ; accepted conn: 190460 ; listen queue: 0 ; max listen queue: 1 ; listen queue len: 42 ; idle processes: 4 ; active processes: 11 ; total processes: 15 ; max active processes: 12 ; max children reached: 0 ; ; By default the status page output is formatted as text/plain. Passing either ; 'html', 'xml' or 'json' in the query string will return the corresponding ; output syntax. Example: ; http://www.foo.bar/status ; http://www.foo.bar/status?json ; http://www.foo.bar/status?html ; http://www.foo.bar/status?xml ; ; By default the status page only outputs short status. Passing 'full' in the ; query string will also return status for each pool process. ; Example: ; http://www.foo.bar/status?full ; http://www.foo.bar/status?json&full ; http://www.foo.bar/status?html&full ; http://www.foo.bar/status?xml&full ; The Full status returns for each process: ; pid - the PID of the process; ; state - the state of the process (Idle, Running, ...); ; start time - the date and time the process has started; ; start since - the number of seconds since the process has started; ; requests - the number of requests the process has served; ; request duration - the duration in µs of the requests; ; request method - the request method (GET, POST, ...); ; request URI - the request URI with the query string; ; content length - the content length of the request (only with POST); ; user - the user (PHP_AUTH_USER) (or '-' if not set); ; script - the main script called (or '-' if not set); ; last request cpu - the %cpu the last request consumed ; it's always 0 if the process is not in Idle state ; because CPU calculation is done when the request ; processing has terminated; ; last request memory - the max amount of memory the last request consumed ; it's always 0 if the process is not in Idle state ; because memory calculation is done when the request ; processing has terminated; ; If the process is in Idle state, then informations are related to the ; last request the process has served. Otherwise informations are related to ; the current request being served. ; Example output: ; ************************ ; pid: 31330 ; state: Running ; start time: 01/Jul/2011:17:53:49 +0200 ; start since: 63087 ; requests: 12808 ; request duration: 1250261 ; request method: GET ; request URI: /test_mem.php?N=10000 ; content length: 0 ; user: - ; script: /home/fat/web/docs/php/test_mem.php ; last request cpu: 0.00 ; last request memory: 0 ; ; Note: There is a real-time FPM status monitoring sample web page available ; It's available in: /usr/local/php/share/php/fpm/status.html ; ; Note: The value must start with a leading slash (/). The value can be ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set pm.status_path = /fpm_status |
发表评论