php-status监控流程

1.开启php的状态页功能

#基于php-fpm进程做的实验

yum install php-fpm -y

修改配置文件,开启php,status功能即可,打开如下参数即可
要求你访问php状态页面的入口就是/status_php

[root@web-7 ~]#grep 'status_'  /etc/php-fpm.d/www.conf 
pm.status_path = /status_php

php-fpm,nginx转发过去的
  1. 设置nginx转发
[root@web-7 /etc/nginx/conf.d]#cat status.conf 
server{

listen 80;
server_name localhost;
location /nginx_status {
stub_status on;
access_log off;
}


location /php_status {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;
    include fastcgi_params;

}


}

重启nginx,和php-fpm俩进程

[root@web-7 ~]#systemctl restart php-fpm.service nginx.service 

访问测试php_status

字段解释

[root@web-7 /etc/nginx/conf.d]#curl 127.0.0.1/php_status
pool:                 www
process manager:      dynamic
start time:           04/Jul/2022:17:27:43 +0800
start since:          158
accepted conn:        2
listen queue:         0
max listen queue:     0
listen queue len:     128
idle processes:       4
active processes:     1
total processes:      5
max active processes: 1
max children reached: 0
slow requests:        0
[root@web-7 /etc/nginx/conf.d]#


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,缓慢请求的数量

自定义的key php_status[采集的关键字]

UserParameter=php_status[*],/etc/zabbix/zabbix_agentd.d/php_status.sh  $1

写脚本简单的监控php-fpm状态值的脚本

#!/bin/bash
# 这是一个简单的监控php-fpm状态值的脚本

comm_para=$1
PHP_URL=$2
cmd="/usr/bin/curl $url"
cachefile=/tmp/php_status.txt
port=80

file_time=`stat -c %Y $cachefile`
now_time=`date +%s`
rm_file=$(($now_time-$file_time))
if [ -z $2 ];then
    url=http://127.0.0.1:$port/status_php
else
    url=$PHP_URL
fi
cmd="/usr/bin/curl $url"

if [ ! -e $cachefile ];then
    $cmd > $cachefile 2>/dev/null
fi

if [ $rm_file -gt 60 ];then
    rm -rf $cachefile
fi

if [ ! -f $cachefile ];then
    $cmd > $cachefile 2>/dev/null
fi

start_since() {
    #运行时长
    cat $cachefile | awk '/since/{print $3}'
    exit 0;
}

accepted_conn() {
    cat $cachefile | awk '/accepted/{print $3}'
    exit 0;
}

listen_queue(){ 
        cat $cachefile | awk '{if(NR==6){print $3}}'
    exit 0;
}

max_listen_queue(){
    cat $cachefile | awk '{if(NR==7){print $4}}'
    exit 0;
}

listen_queue_len() {
    cat $cachefile | awk '{if(NR==8){print $4}}'
    exit 0;
}

idle_processes() {
    cat $cachefile | awk '/idle/{print $3}'
    exit 0;
}

active_processes() {
    cat $cachefile | awk '{if(NR==10){print $3}}'
    exit 0;
}

total_processes() {
    cat $cachefile | awk '{if(NR==11){print $3}}'
        exit 0;
}

max_active_processes() {
    cat $cachefile | awk '{if(NR==12){print $4}}'
        exit 0;
}

max_children_reached() {
    cat $cachefile | awk '{if(NR==13){print $4}}'
        exit 0;
}

slow_requests() {
    cat $cachefile | awk '{if(NR==14){print $3}}'
        exit 0;
}

check() {
        php_pro_count=`ss -tunlp|grep php-fpm|wc -l`
        echo $php_pro_count
}

case "$comm_para" in 
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
    ;;
slow_requests)
    slow_requests
    ;;
check)
    check
    ;;
*)    
    echo "invalid status"
    exit 2;
esac

改权限

[root@web-7 /etc/zabbix/zabbix_agentd.d]#chmod +x php_status.sh 
[root@web-7 /etc/zabbix/zabbix_agentd.d]#chown -R zabbix.zabbix ./*
[root@web-7 /etc/zabbix/zabbix_agentd.d]#ll
total 20
-rw-r--r-- 1 zabbix zabbix   87 Jul  4 13:44 nginx_status.conf
-rwxr-xr-x 1 zabbix zabbix 1706 Jul  4 13:51 nginx_status.sh
-rwxr-xr-x 1 zabbix zabbix 1095 Jul  4 17:33 php_status.sh
-rw-r--r-- 1 zabbix zabbix   52 Jun 29 19:06 tcp_status.conf
-rw-r--r-- 1 zabbix zabbix 1531 Jul 29  2019 userparameter_mysql.conf
3. 重启agent
[root@web-7 /etc/zabbix/zabbix_agentd.d]#systemctl restart zabbix-agent.service 

4.手动zabbix_get测数据
[root@zabbix-server-71 ~]#zabbix_get -s 10.0.0.7 -k php_status[total_processes]
5

配置zabbix-UI的模板

监控项克隆添加
关联web7机器
添加图形数据,给模板加
查看web7的图形数据即可

添加触发器,判断php如果挂了, 立即钉钉报警

判断php-fpm进程挂了立即钉钉报警

posted @   不太聪明的大鹅  阅读(39)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示