Zabbix学习笔记(四十七)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zabbix学习笔记(四十七)相关的知识,希望对你有一定的参考价值。
Zabbix学习笔记(四十七)-zabbix监控php-fpm状态
1、修改配置文件
/etc/php-fpm.d/www.conf
;pm.status_path = /status 修改为pm.status_path = /php_status
/etc/nginx/nginx.conf增加:
location /php_status
fastcgi_pass unix:/run/php-fpm/www.sock;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
重启服务
systemctl restart php-fpm.service nginx.service
浏览器:
http://10.41.1.88/php_status
数据说明:
pool(资源池名): www
process manager(进程管理方式): dynamic(动态)
start time(启动时间): 17/Mar/2021:10:43:25 +0800
start since(持续运行时间): 50
accepted conn(接受的请求次数): 1
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
2、编写监控脚本
cat php_monitor.sh
#!/bin/bash
PHP_COMMAND=$1
CMD="/usr/bin/curl -s http://127.0.0.1/php_status"
#check
start_since()
$CMD |awk /since/ print $3
exit 0;
accepted_conn()
$CMD |awk /accepted/ print $3
exit 0;
listen_queue()
$CMD |awk /^listen queue/ print $0|awk !/len/ print $3
exit 0;
max_listen_queue()
$CMD |awk /max listen/ print $4
exit 0;
listen_queue_len()
$CMD |awk /len/ print $4
exit 0;
idle_processes()
$CMD |awk /idle/ print $3
exit 0;
active_processes()
$CMD |awk /^active/ print $3
exit 0;
total_processes()
$CMD |awk /^total/ print $3
exit 0;
max_active_processes()
$CMD |awk /max active/ print $4
exit 0;
max_children_reached()
$CMD |awk /children/ print $4
exit 0;
slow_requests()
$CMD |awk /slow/ print $3
exit 0;
check()
ps -ef|grep -v grep|grep -c php-fpm
exit 0;
case "$PHP_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
;;
check)
check
;;
*)
echo "invalid status"
exit 2;
esac
3、客户端配置文件
/etc/zabbix/zabbix_agentd.d/zbx_php.conf
UserParameter=php_status[*],/bin/bash /root/php_monitor.sh $1
重启zabbix-agent
4、配置php监控模板
5、监控主机链接php监控模板
以上是关于Zabbix学习笔记(四十七)的主要内容,如果未能解决你的问题,请参考以下文章