php-fpm和nginx一样内建了一个状态页,对于想了解php-fpm的状态以及监控php-fpm非常有帮助
- 启用php-fpm状态功能
修改php-fpm配置文件,确保如下配置是打开状态
pm.status_path = /status,具体操作如下
在Zabbix-server端操作如下
cd /usr/local/php/etc
ls
sed -n '360p' php-fpm.conf
vim php-fpm.conf +360
sed -n '360p' php-fpm.conf
![d663ee7a39255321fd31788fb10e50b9.png](https://i-blog.csdnimg.cn/blog_migrate/bdc615a3748465677e4176e77c1a6b6d.jpeg)
重启php-fpm服务
netstat -antup | grep php-fpm
pkill php-fpm
netstat -antup | grep php-fpm
/usr/local/php/sbin/php-fpm
netstat -antup | grep php-fpm
![66791bf19a5b587f1623ab303047c752.png](https://i-blog.csdnimg.cn/blog_migrate/d96a489950a1c4f1e99c04c340978d41.jpeg)
- nginx配置php-fpm状态页面
配置php-fpm状态页面
vim /usr/local/nginx/conf/nginx.conf
cat /usr/local/nginx/conf/nginx.conf
1. worker_processes 1;
2. events {
3. worker_connections 1024;
4. }
5. http {
6. include mime.types;
7. default_type application/octet-stream;
8. sendfile on;
9. keepalive_timeout 65;
10. server {
11. listen 80;
12. server_name localhost;
13. location / {
14. root html;
15. index index.php index.html index.htm;
16. }
17. location = /nginx-status {
18. stub_status on;
19. access_log off;
20. }
21. location = /status { #添加此location
22. include fastcgi_params;
23. fastcgi_pass 127.0.0.1:9000;
24. fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
25. }
26. location ~ .php$ {
27. fastcgi_pass 127.0.0.1:9000;
28. fastcgi_index index.php;
29. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
30. include fastcgi_params;
31. }
32. }
33. }
![c1861e08ceea4889181c38310b5a8cb5.png](https://i-blog.csdnimg.cn/blog_migrate/a67dcd390e50de304afae6e0afcd4b8e.jpeg)
重启动nginx服务
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
![8ea58085bd18f65b5e65f5f5c98e9610.png](https://i-blog.csdnimg.cn/blog_migrate/012e557b8f843e55798f0e9594bbdb91.jpeg)
- 状态页浏览器访问测试
php-fpm状态页比较个性化的一个地方是它可以带参数,可以带的参数有json、xml、html,使用zabbix或者nagios监控可以考虑使用xml或者默认方式。
![6f1b80b585b5b2713432da6a42d60a77.png](https://i-blog.csdnimg.cn/blog_migrate/038fd743522e9ebf222fff9a417538f7.jpeg)
具体含义说明如下
curl 127.0.0.1/status
1. pool: www #fpm进程池名称,大多数为www
2. process manager: dynamic #进程管理方式(static,dynamic or nodemand.dynamic)
3. start time: 12/Dec/2018:07:35:24 +0800 #启动日期
4. start since: 1137 #运行时长
5. accepted conn: 142 #当前FPM进程池接受的请求数
6. listen queue: 0 #请求等待队列,如果值不是0,那么要增加FPM的进程数
7. max listen queue: 0 #请求等待队列最高的数量
8. listen queue len: 128 #socket等待队列长度
9. idle processes: 1 #空闲进程数量
10. active processes: 1 #活跃进程数量
11. total processes: 2 #总进程数量
12. max active processes: 2 #最大的活跃进程数量(FPM启动开始算)
13. max children reached: 0 #达到最大子进程的次数,如果值不为0,那么需要调高最大进程数
14. slow requests: 0 #当启用了php-fpm的slow-log功能时,如果出现php-fpm慢请求这个计数器会增加,一般不当的MySQL查询会触发这个值
![d3d08cc78eed69062bdff7410de06b91.png](https://i-blog.csdnimg.cn/blog_migrate/8f62bafe15977f4857904ea28ce49a67.jpeg)
其他状态参数显示形式的数据(json,xml,html)
以xml的格式输出PHP-fpm状态页
curl 127.0.0.1/status?xml
1. <?xml version="1.0" ?>
2.
3. www
4. dynamic
5. 1516953418
6. 3731
7. 647
8. 0
9. 4
10. 128
11. 2
12. 1
13. 3
14. 3
15. 0
16. 0
![906ed7613ca46f499078522cfaa27ec7.png](https://i-blog.csdnimg.cn/blog_migrate/aecea08518bf924e1c72681b361dac0d.jpeg)
以json的格式输出PHP-fpm的状态页
curl 127.0.0.1/status?json
1. {"pool":"www","process manager":"dynamic","start time":1516953418,"start since":3736,"accepted conn":648,"listen queue":0,"max listen queue":4,"listen queue len":128,"idle processes":2,"active processes":1,"total processes":3,"max active processes":3,"max children reached":0,"slow requests":0}[root@Zabbix_Server nginx]#
![6fb0f87fd09fb8b1fc8db54c0aa601b0.png](https://i-blog.csdnimg.cn/blog_migrate/d69bdc7b5c904e422304757185421923.jpeg)
以html的格式输出PHP-fpm的状态页
curl 127.0.0.1/status?html
1.
2.
3.
PHP-FPM Status Page4.
5.
6.
poolwww7.
process managerdynamic8.
start time26/Jan/2018:02:56:58 -05009.
start since374810.
accepted conn65011.
listen queue012.
max listen queue413.
listen queue len12814.
idle processes215.
active processes116.
total processes317.
max active processes318.
max children reached019.
slow requests020.
21.
![70dd6062cb3a22814e8c8e7664ffddf9.png](https://i-blog.csdnimg.cn/blog_migrate/1490affce6742d76c8b36fffc9152eaa.jpeg)
- 在Zabbix agent端修改配置
在创建Zabbix的agent端键值配置文件的时候,我们可以考虑利用PHP-fpm状态页的不同输出格式来抓取数据。例如我们利用xml格式获取数据,操作如下:
查看xml格式PHP-fpm状态页数据
curl 127.0.0.1/status?xml
1. <?xml version="1.0" ?>
2.
3. www
4. dynamic
5. 1516953418
6. 3731
7. 647
8. 0
9. 4
10. 128
11. 2
12. 1
13. 3
14. 3
15. 0
16. 0
![ea66a34abef5d277bb752b96154da444.png](https://i-blog.csdnimg.cn/blog_migrate/0ce9862c6af1a551044ea703334016f6.jpeg)
创建zabbix监控的agent端键值配置文件
cd /etc/zabbix/zabbix_agentd.d/
vim userparameter_php-fpm.conf
cat userparameter_php-fpm.conf
1. UserParameter=php-fpm.status[*],/usr/bin/curl -s "http://127.0.0.1/status?xml" | grep "" | awk -F "[>|
2.
3. 这里需要注意在脚本里如果写成$3的话,脚本会认识是一个变量,因此我们需要用$$3
![c128ca7a46a2e4717874fd2e77adc608.png](https://i-blog.csdnimg.cn/blog_migrate/b0fe03249079d039c5cb68f750139861.jpeg)
重启动agent客户端
/etc/init.d/zabbix-agent restart
![cf7590b688adebc70cfcb1934b423415.png](https://i-blog.csdnimg.cn/blog_migrate/8d663a3efc38f9d724c832147c94f755.jpeg)
- 进行键值配置文件测试
zabbix_get -s 192.168.200.69 -p 10050 -k "php-fpm.status[process-manager]"
zabbix_get -s 192.168.200.69 -p 10050 -k "php-fpm.status[start-since]"
zabbix_get -s 192.168.200.69 -p 10050 -k "php-fpm.status[active-processes]"
![8b87137780a5ad4fb87fe86147cfed5b.png](https://i-blog.csdnimg.cn/blog_migrate/f2aec70f577c020adb7b425d1ba72c55.jpeg)
- Zabbix图形界面导入我们的监控模版(上边有模板下载链接)
![33f3562952f41c4597f76e4c8a3727bb.png](https://i-blog.csdnimg.cn/blog_migrate/0da812534f01948a5c54cffc97d163c8.jpeg)
![64ce14ec16d7de2d38e172cd47a568bf.png](https://i-blog.csdnimg.cn/blog_migrate/15aab9c1ae8e512173c9b03acb956689.jpeg)
![5fa09da95d2ac3e4aa0bd5bf8881b78c.png](https://i-blog.csdnimg.cn/blog_migrate/19ec6e18c7d5e3b1902c238b0e93dc96.jpeg)
![bbab68a9c08dfc23cd817639a7273a2c.png](https://i-blog.csdnimg.cn/blog_migrate/44dcc7b381ff8a77fcaadd87fdcef8b4.jpeg)
![e9177868e581a477327da1163ad4e153.png](https://i-blog.csdnimg.cn/blog_migrate/bb79f253c3dedfdf2a35c2f0f508bd62.jpeg)