修改配置文件
- 编辑php-fpm配置文件
[root@web03 ~]# vim /etc/php-fpm.d/www.conf
pm.status_path = /phpfpm_status
重启php-fpm服务
systemctl restart php-fpm
- 配置nginx配置文件
在nginx配置文件当中,加入一个location
[root@web03 conf.d]# cat status.conf
server {
listen 80;
server_name _;
#获取php-fpm状态
location /phpfpm_status {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#获取nginx状态
location /nginx_status {
stub_status on;
}
}
重启nginx服务
systemctl restart nginx
编写获取php-fpm状态的脚本
cat /server/scripts/phpfpm_status.sh
#!/bin/bash
PHPFPM_COMMAND=$1
PHPFPM_PORT=80
start_since(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^start since:/ {print $NF}'
}
accepted_conn(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^accepted conn:/ {print $NF}'
}
listen_queue(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue:/ {print $NF}'
}
max_listen_queue(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max listen queue:/ {print $NF}'
}
listen_queue_len(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^listen queue len:/ {print $NF}'
}
idle_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^idle processes:/ {print $NF}'
}
active_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^active processes:/ {print $NF}'
}
total_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^total processes:/ {print $NF}'
}
max_active_processes(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max active processes:/ {print $NF}'
}
max_children_reached(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^max children reached:/ {print $NF}'
}
slow_requests(){
/usr/bin/curl -s "http://127.0.0.1:"$PHPFPM_PORT"/phpfpm_status" |awk '/^slow requests:/ {print $NF}'
}
case $PHPFPM_COMMAND 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;
;;
*)
echo $"USAGE:$0 {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
给脚本添加执行权限
chmod +x /server/scripts/redis.sh
配置获取状态的key
[root@web03 ~]# cat /etc/zabbix/zabbix_agentd.d/phpfpm_status.conf
UserParameter=phpfpm_status[*],/bin/bash /server/scritps/phpfpm_status.sh "$1"
重启agent服务
systemctl restart zabbix-agent.service
测试是否可以获得key值
#在agent端测试
[root@web03 ~]# zabbix_agentd -t phpfpm_status[accepted_conn]
phpfpm_status[accepted_conn] [t|107]
#在服务端测试
[root@zabbix-server ~]# zabbix_get -s 172.16.1.9 -p 10050 -k phpfpm_status[accepted_conn]
182
web界面导入模板
- 查看导入好后的的数据信息
先把模板关联到web03这台主机上
文档更新时间: 2020-12-28 19:02 作者:Wan Hebin