標籤:php監控
入職以後,領導讓我著手zabbix監控的部署和具體的維護。監控php首先就是一個挺重要的事情了。zabbix監控php可以通過php內建的一個status功能來監控,需要在設定檔裡面開啟,同時在nginx裡面配置php status可以訪問
1.php-fpm 開啟status
grep pm.status_path /usr/local/php/etc/php-fpm.confpm.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池子名稱,大多數為wwwprocess manager – 進程管理方式,值:static, dynamic or ondemand. dynamicstart 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 配置
[[email protected] zabbix_agentd.conf.d]# cat check_php_status.conf UserParameter=php-fpm.status[*],/etc/zabbix/alertscripts/php_status.sh $1UserParameter=php_status,ps -ef | grep php-fpm | awk ‘{ print $9}‘ | grep master | wc -lUserParameter=process.php.memory,/home/hckjS213/zabbix/etc/script/processstatus.sh phpmemUserParameter=process.php.cpu,/home/hckjS213/zabbix/etc/script/processstatus.sh phpcpuUserParameter=process.php.num,/home/hckjS213/zabbix/etc/script/processstatus.sh phpnum
5.編寫php監控指令碼
#!/bin/bashCURL=`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" == "" ];thenecho 0elseecho $outputfi }$1
php進程資源使用率指令碼
#!/bin/bash#chck for php and sphinx used cpu and memoryphpmem(){ 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" inphpmem)phpmem;;phpcpu)phpcpu;;phpnum)phpnum;;*)echo "Usage: $0 {phpmem|phpcpu|phpnum}"esac
6.測試
[[email protected]_server ~]#/usr/local/zabbix/bin/zabbix_get -s 192.168.50.119 -k php-fpm.status[active] 1[[email protected]_server ~]# zabbix_get -s 10.144.164.53 -p 10050 -k process.php.memory 2070688
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/8B/97/wKiom1hSD6ezT2G_AACPEZHIDFc105.png" title="eae22684-b027-483f-a42e-a545faddf594.png" alt="wKiom1hSD6ezT2G_AACPEZHIDFc105.png" />
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/8B/93/wKioL1hSD9qBT6MbAACPW9hXpLE213.png" title="QQ圖片20161215113650.png" alt="wKioL1hSD9qBT6MbAACPW9hXpLE213.png" />
本文出自 “不拋棄!不放棄” 部落格,請務必保留此出處http://thedream.blog.51cto.com/6427769/1882958
zabbix監控php-status和進程資源使用率