1.开启php的监控数据监控功能
# 使用部署了php-fpm的机器即可
# yum install php-fpm -y
安装报错就是遇到了php版本冲突,卸载老版本,如:
rpm -qa|grep php71w
rpm -e `rpm -qa|grep php71w`
# 1.修改参数
[root@web-7 /etc/php-fpm.d]#grep '^pm.status' /etc/php-fpm.d/www.conf
pm.status_path = /php_status
2. 设置nginx转发
[root@web-7 /etc/nginx/conf.d]#cat status.conf
server{
listen 80;
server_name localhost;
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;
}
}
3.重启nginx,php-fpm
[root@web-7 /etc/nginx/conf.d]#systemctl restart nginx php-fpm
[root@web-7 /etc/nginx/conf.d]#netstat -tunlp|grep -E 'php|nginx'
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 51059/php-fpm: mast
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 51076/nginx: master
tcp6 0 0 :::80 :::* LISTEN 51076/nginx: master
2.访问测试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,缓慢请求的数量
3.脚本提取监控页面数据
#!/bin/bash
PHP_STATUS=$1
PHPFILE="/tmp/php_status.txt"
CMD="curl http://10.0.0.7:8081/php_status"
TIMEFILE=$(stat -c %Y $PHPFILE)
TIMENOW=$(date +%s)
function PHPFILE_IS_EXIST(){
if [ ! -f $PHPFILE ];then
$CMD > $PHPFILE 2>/dev/null
fi
}
PHPFILE_IS_EXIST
if [ $[ $TIMENOW - $TIMEFILE ] -gt 60 ];then
rm -f $PHPFILE
PHPFILE_IS_EXIST
fi
pool(){
awk 'NR==1{print $NF}' $PHPFILE
}
process_manager(){
awk 'NR==2{print $NF}' $PHPFILE
}
start_time(){
awk 'NR==3{print $(NF-1)}' $PHPFILE
}
start_since(){
awk 'NR==4{print $NF}' $PHPFILE
}
accepted_conn(){
awk 'NR==5{print $NF}' $PHPFILE
}
listen_queue(){
awk 'NR==6{print $NF}' $PHPFILE
}
max_listen_queue(){
awk 'NR==7{print $NF}' $PHPFILE
}
listen_queue_len(){
awk 'NR==8{print $NF}' $PHPFILE
}
idle_processes(){
awk 'NR==9{print $NF}' $PHPFILE
}
active_processes(){
awk 'NR==10{print $NF}' $PHPFILE
}
total_processes(){
awk 'NR==11{print $NF}' $PHPFILE
}
max_active_processes(){
awk 'NR==12{print $NF}' $PHPFILE
}
max_children_reached(){
awk 'NR==13{print $NF}' $PHPFILE
}
slow_requests(){
awk 'NR==14{print $NF}' $PHPFILE
}
check() {
php_pro_count=`ss -tunlp|grep php-fpm|wc -l`
echo $php_pro_count
}
case $PHP_STATUS in
pool)
pool
;;
process_manager)
process_manager
;;
start_time)
start_time
;;
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 "无效的参数"
;;
esac
放入zabbix-agent目录
[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
-rwxr-xr-x 1 zabbix zabbix 1095 Jul 4 17:33 php_status.sh
4.准备zabbix_agent自定义key配置文件
[root@web-7 /etc/zabbix/zabbix_agentd.d]#cat php_status.conf
UserParameter=php_status[*],/etc/zabbix/zabbix_agentd.d/php_status.sh $1
[root@web-7 /etc/zabbix/zabbix_agentd.d]#systemctl restart zabbix-agent.service
5.zabbix_get验证
[root@m-61 ~]#zabbix_get -s 10.0.0.7 -k php_status[listen_queue_len]
128
[root@m-61 ~]#zabbix_get -s 10.0.0.7 -k php_status[start_since]
1322
6.配置zabbix-UI的模板
创建模板
修改zabbix的宏,也就是我们自定义的status页面访问的入口url。
创建应用集、监控项
![image-20220704175415629](C:\Users\18132\Desktop\image-20220704175415629.png克隆即可
其他监控项配置一致,只是参数key值不一样
所有监控项key值
php_status[start_since,{$PHP_URL}]
php_status[accepted_conn,{$PHP_URL}]
php_status[listen_queue,{$PHP_URL}]
php_status[max_listen_queue,{$PHP_URL}]
php_status[listen_queue_len,{$PHP_URL}]
php_status[idle_processes,{$PHP_URL}]
php_status[active_processes,{$PHP_URL}]
php_status[total_processes,{$PHP_URL}]
php_status[active_processes,{$PHP_URL}]
php_status[max_active_processes,{$PHP_URL}]
php_status[max_children_reached,{$PHP_URL}]
php_status[slow_requests,{$PHP_URL}]
php_status[check,{$PHP_URL}]
6.2 触发器添加
针对php-fpm进程状态加一个触发器,防止该进程挂了
6.3 创建图形
6.4 主机使用模板
6.5 查看最新数据、图形
6.6 php-fpm挂了报警
[root@web-7 /etc/zabbix/zabbix_agentd.d]#systemctl stop php-fpm
标签:status,processes,php,zabbix,PHPFILE,Zabbix,监控,PHP,listen
From: https://www.cnblogs.com/chunjeh/p/17748267.html