使用监控宝监控php-fpm状态

上次我们介绍如何开启php-fpm的状态页,这对于php-fpm的参数调整有很高的参考价值。我们可以使用监控宝的自定义监控来保存php-fpm的状态,来达到了解网站各时候php的请求情况。在开始之前,请确保已经开启php-fpm的status。
一、创建收集数据脚本
新建脚本/home/sh/monitor_fpm.sh,并添加到cronjob,每五分钟运行一次。脚本代码为:
fpm_status=$(curl -s https://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 ”

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

” > /home/www.centos.bz/web/php_status.html
二、到监控宝添加自定义监控
1、点击网站头部的创建监控项目,拉到底部,选择创建自定义监控,再点击创建自定义监控规则,
2、基本信息填写

3、规则指标添加

3、添加php请求图

4、添加php进程图

5、添加php最大值图

6、点击完成,输入监控fpm的页面

完成了以上步骤之后,过一段时间就可以看到php-fpm的状态统计信息了。
如图:

标签:PHP监控 发布于:2019-11-22 05:56:48