上次我们介绍如何开启php-fpm状态页了,这对于php-fpm的参数调整有很高的参考价值。我们可以使用监控宝的自定义监控来保存php-fpm的状态,来达到了解网站各时候php的请求情况。在开始之前,请确保已经开启php-fpm的status。
一、创建收集数据脚本
新建脚本/home/sh/monitor_fpm.sh,并添加到cronjob,每五分钟运行一次。脚本代码为:
- fpm_status=$(curl -s http://www.centos.bz/fpm_status)
- start_since_now=$(echo “$fpm_status” | awk -F’:’ ‘/start since/{gsub(/ /,””,$2);print $2}’)
- listen_queue=$(echo “$fpm_status” | awk -F’:’ ‘/^listen queue:/{gsub(/ /,””,$2);print $2}’)
- idle_processes=$(echo “$fpm_status” | awk -F’:’ ‘/idle processes/{gsub(/ /,””,$2);print $2}’)
- active_processes=$(echo “$fpm_status” | awk -F’:’ ‘/^active processes:/{gsub(/ /,””,$2);print $2}’)
- total_processes=$(echo “$fpm_status” | awk -F’:’ ‘/total processes/{gsub(/ /,””,$2);print $2}’)
- accepted_conn_now=$(echo “$fpm_status” | awk -F’:’ ‘/accepted conn/{gsub(/ /,””,$2);print $2}’)
- max_listen_queue=$(echo “$fpm_status” | awk -F’:’ ‘/max listen queue/{gsub(/ /,””,$2);print $2}’)
- max_active_processes=$(echo “$fpm_status” | awk -F’:’ ‘/max active processes/{gsub(/ /,””,$2);print $2}’)
- max_children_reached=$(echo “$fpm_status” | awk -F’:’ ‘/max children reached/{gsub(/ /,””,$2);print $2}’)
- if [ -f “/tmp/accepted_conn78” ];then
- accepted_conn_pre=$(cat /tmp/accepted_conn78)
- ((accepted_conn_inc=$accepted_conn_now – $accepted_conn_pre))
- [[ $accepted_conn_inc -lt 0 ]] && accepted_conn_inc=0
- else
- accepted_conn_inc=0
- fi
- echo $accepted_conn_now > /tmp/accepted_conn78
- if [ -f “/tmp/start_since78” ];then
- start_since_pre=$(cat /tmp/start_since78)
- ((start_since_inc=$start_since_now – $start_since_pre))
- [[ $start_since_inc -lt 0 ]] && per_request=0 || ((per_request=$accepted_conn_inc/$start_since_inc))
- else
- per_request=0
- fi
- echo $start_since_now > /tmp/start_since78
- echo “<pre>
- accepted_conn:$accepted_conn_inc
- listen_queue:$listen_queue
- idle_processes:$idle_processes
- active_processes:$active_processes
- total_processes:$total_processes
- per_request:$per_request
- max_listen_queue:$max_listen_queue
- max_active_processes:$max_active_processes
- max_children_reached:$max_children_reached
- </pre>” > /home/www.centos.bz/web/php_status.html
二、到监控宝添加自定义监控
1、点击网站头部的创建监控项目,拉到底部,选择创建自定义监控,再点击创建自定义监控规则,
2、基本信息填写
3、规则指标添加
3、添加php请求图
4、添加php进程图
5、添加php最大值图
6、点击完成,输入监控fpm的页面
完成了以上步骤之后,过一段时间就可以看到php-fpm的状态统计信息了。
如图:
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/58101.html