Zabbix实战-简易教程--WEB类--Php-fpm
Php-fpm的监控过程和监控Nginx如出一辙,同样是以下几个步骤。
一、开启php-fpm status状态
1、在默认主机里面加上location添加phpfpmstatus
location ~ ^/(phpfpmstatus)$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name; include fastcgi_params; }
2、重启php-fpm服务,service php-fpm restart,查看取值是否正常。
curl -s http://127.0.0.1:8080/phpfpmstatus
pool: www process manager: dynamic start time: 27/Jun/2016:18:57:48 +0800 start since: 39923567 accepted conn: 230619929 listen queue: 0 max listen queue: 0 listen queue len: 0 idle processes: 32 active processes: 3 total processes: 35 max active processes: 50 max children reached: 24 slow requests: 0
3、 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,缓慢请求的数量
二、编写获取php-fpm status的脚本
#!/bin/bash pool(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/pool/ {print $NF}' } process_manager() { curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/process manager/ {print $NF}' } start_since(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^start since:/ {print $NF}' } accepted_conn(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^accepted conn:/ {print $NF}' } listen_queue(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^listen queue:/ {print $NF}' } max_listen_queue(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^max listen queue:/ {print $NF}' } listen_queue_len(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^listen queue len:/ {print $NF}' } idle_processes(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^idle processes:/ {print $NF}' } active_processes(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^active processes:/ {print $NF}' } total_processes(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^total processes:/ {print $NF}' } max_active_processes(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^max active processes:/ {print $NF}' } max_children_reached(){ curl -s http://127.0.0.1:8080/phpfpmstatus|awk '/^max children reached:/ {print $NF}' } case "$1" in pool) pool ;; process_manager) process_manager ;; start_since) start_since ;; accepted_conn) accepted_conn ;; listen_queue) listen_queue ;; max_listen_queue) max_listen_queue ;; listen_queue_len) listen_queue_len ;; idle_processes) idle_processes ;; active_processes) active_processes ;; total_processes) total_processes ;; max_active_processes) max_active_processes ;; max_children_reached) max_children_reached ;; *) echo "Usage: $0 {pool|process_manager|start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_processes|active_processes|total_processes|max_active_processes|max_children_reached}" esac
Agent端写入自定义key:
UserParameter=php-fpm[*], /bin/bash /etc/zabbix/externalscripts/monitor-fpm.sh $1
三、制作php-fpm模板
根据上面的监控项制作好模板,模板已经上传至Github:https://github.com/loveqx/zabbix-doc/blob/master/zabbix-scripts/zabbix-template-php-fpm/Template%20App%20For%20php-fpm.xml
具体监控项如下:
四、模板上套
五、效果图
最后附上监控需要的模板和脚本:
Php-fpm监控github地址: