您好,登錄后才能下訂單哦!
入職以后,領導讓我著手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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。