您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
入职以后,领导让我着手zabbix监控的部署和具体的维护。监控php首先就是一个挺重要的事情了。zabbix监控php可以通过php自带的一个status功能来监控,需要在配置文件里面开启,同时在nginx里面配置php status可以访问
1.php-fpm 开启status
grep pm.status_path /usr/local/php/etc/php-fpm.conf pm.status_path = /php-fpm-status
默认情况下为/status,当然也可以改成/phpfpm_status等,我这里是改成/php-fpm-status
2.nginx配置
server { listen 80; server_name 127.0.0.1; location /phpfpm_status { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } }
3.php status详解
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,缓慢请求的数量
4.添加zabbix_agent 配置
[root@localhost zabbix_agentd.conf.d]# cat check_php_status.conf UserParameter=php-fpm.status[*],/etc/zabbix/alertscripts/php_status.sh $1 UserParameter=php_status,ps -ef | grep php-fpm | awk '{ print $9}' | grep master | wc -l UserParameter=process.php.memory,/home/hckjS213/zabbix/etc/script/processstatus.sh phpmem UserParameter=process.php.cpu,/home/hckjS213/zabbix/etc/script/processstatus.sh phpcpu UserParameter=process.php.num,/home/hckjS213/zabbix/etc/script/processstatus.sh phpnum
5.编写php监控脚本
#!/bin/bash CURL=`which curl` function idle { $CURL "http://127.0.0.1/php-fpm-status" 2>/dev/null| grep -w '^idle processes:' | awk '{print $3}' } function total { $CURL "http://127.0.0.1/php-fpm-status" 2>/dev/null| grep -w '^total processes:' | awk '{print $3}' } function active { $CURL "http://127.0.0.1/php-fpm-status" 2>/dev/null| grep -w '^active processes:' | awk '{print $3}' } function listen_queue { $CURL "http://127.0.0.1/php-fpm-status" 2>/dev/null| grep -w "^listen queue:" | awk '{print $3}' } function slow_requests { output=` $CURL "http://127.0.0.1/php-fpm-status" 2>/dev/null| grep -w "^slow requests:"| awk '{print $3}'` if [ "$output" == "" ];then echo 0 else echo $output fi } $1
php进程资源使用率脚本
#!/bin/bash #chck for php and sphinx used cpu and memory phpmem(){ ps aux|grep "php"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$6}; END{print sum}' } phpcpu(){ ps aux|grep "php"|grep -v "grep"|grep -v "processstatus.sh"|awk '{sum+=$3}; END{print sum}' } phpnum(){ ps aux|grep "php"|grep -v "grep"|grep -v "processstatus.sh"| wc -l } case "$1" in phpmem) phpmem ;; phpcpu) phpcpu ;; phpnum) phpnum ;; *) echo "Usage: $0 {phpmem|phpcpu|phpnum}" esac
6.测试
[root@Zabbix_server ~]#/usr/local/zabbix/bin/zabbix_get -s 192.168.50.119 -k php-fpm.status[active] 1 [root@Zabbix_server ~]# zabbix_get -s 10.144.164.53 -p 10050 -k process.php.memory 2070688
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。