zabbix監控php-fpm的性能

zabbix經過自定義item監控php-fpm性能狀況作觸發器,作圖形,發郵件php

首先php-fpm的性能數據是要經過頁面獲取,因此須要在php-fpm的配置文件中添加一下語句html

通常在/usr/local/php/etc/php-fpm.confnginx

pm.status_path = /statusjson

重啓php-fpmvim

在nginx的配置文件中加入頁面匹配bash

/usr/local/nginx/conf/nginx.confcurl

location ~ ^/(status|ping)$
    {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; socket

}php-fpm

重啓nginx性能

curl http://127.0.0.1/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,緩慢請求的數量

php-fpm狀態頁比較個性化的一個地方是它能夠帶參數,能夠帶參數json、xml、html而且前面三個參數能夠分別和full作一個組合。用了以上參數能夠得到知道格式的頁面

curl http://127.0.0.1/status?json

curl http://127.0.0.1/status?xml

curl http://127.0.0.1/status?html

curl http://127.0.0.1/status?full

參數full詳解

pid – 進程PID,能夠單獨kill這個進程. You can use this PID to kill a long running process.
state – 當前進程的狀態 (Idle, Running, …)
start time – 進程啓動的日期
start since – 當前進程運行時長
requests – 當前進程處理了多少個請求
request duration – 請求時長(微妙)
request method – 請求方法 (GET, POST, …)
request URI – 請求URI
content length – 請求內容長度 (僅用於 POST)
user – 用戶 (PHP_AUTH_USER) (or ‘-’ 若是沒設置)
script – PHP腳本 (or ‘-’ if not set)
last request cpu – 最後一個請求CPU使用率。
last request memorythe - 上一個請求使用的內存

接着經過自定義item,加腳本,模板就能夠經過zabbix監控性能

添加監控的shlle腳本
php-fpm_status.sh
添加zabbix-agent配置
php-fpm_status.conf
重啓zabbix-agent
service zabbix-agent restart
測試
zabbix_get -s 127.0.0.1 -k slow.requests
若是沒有問題導入模板
php-fpm_status.xml

腳本

listenqueue(){

         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "listen queue:" | grep -vE "len|max" | awk '{print$3}'
}
 
listenqueuelen(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "listen queue len" | awk '{print$4}'
}
 
idle(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "idle processes" | awk '{print$3}'
}
active(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "active" | awk '{print$3}' | grep - v "process"
}
total(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "total processes" | awk '{print$3}'
}
 
mactive(){
 
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "max active processes:" | awk '{print$4}'
}
 
since(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "start since: " | awk '{print$3}'
}
 
conn(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "accepted conn" | awk '{print$3}'
}
 
reached(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "max children reached" | awk '{print$4}'
}
requests(){
         wget --quiet -O - http: //127 .0.0.1:80 /status ?auto | grep "slow requests" | awk '{print$3}'
}
$1
 
 
模板
vim php-fpm_status.conf
UserParameter=idle.processe, /scripts/php-fpm_status .sh idle
UserParameter=total.processes, /scripts/php-fpm_status .sh total
UserParameter=active.processes, /scripts/php-fpm_status .sh active
UserParameter=max.active.processes, /scripts/php-fpm_status .sh mactive
UserParameter=listen.queue.len, /scripts/php-fpm_status .sh listenqueuelen
UserParameter=listen.queue, /scripts/php-fpm_status .sh listenqueue
UserParameter=start.since, /scripts/php-fpm_status .sh since
UserParameter=accepted.conn, /scripts/php-fpm_status .sh conn
UserParameter=max.children.reached, /scripts/php-fpm_status .sh reached
 
接着就能夠根據item建立圖形,根據值建立觸發器,根據觸發器發送郵件或進一步作腳本操做
UserParameter=slow.requests, /scripts/php-fpm_status .sh requests
相關文章
相關標籤/搜索