php-fpm和nginx一樣內建了一個狀態頁,對於想了解php-fpm的狀態以及監控php-fpm非常有幫助。為了後續的zabbix監控,我們需要先了解php-fpm狀態頁是怎麼回事。
1. 啟用php-fpm狀態功能
<code><span># cat /usr/local/php-5.5.10/etc/php-fpm.conf | grep status_path</span>
pm.status_path = /status</code>
2. nginx設定
<code>server {
listen *:<span>80</span> default_server;
server_name _;
location ~ ^/(status|ping)$
{
<span><strong>include</strong></span> fastcgi_params;
fastcgi_pass <span>127.0</span><span>.0</span><span>.1</span>:<span>9000</span>;
fastcgi_param SCRIPT_FILENAME <span>$fastcgi_script_name</span>;
}
}</code>
3. 重啟nginx/php-fpm
<code>service nginx restart
service php<span>-fpm</span> restart</code>
4. 開啟status頁面詳解
– 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 – 請求等待<strong>隊列</strong>最高的數量
listen queue len – socket等待
隊列長度
idle processes – 空閒行程數量
active processes – 活躍行程數
total processes – 總進程數
max active processes – 最大的活躍進程數量(FPM啟動開始算)
max children reached
-
大道進程最大數量限制的次數,如果這個數量不為0,那說明你的最大進程數量太小了,請改大一點。
slow requests – 啟用了php-fpm slow-log,緩慢請求的數量
6. php-fpm其他參數
php-fpm狀態頁比較個性化的一個地方是它可以帶參數,可以帶參數
json
、
xml
、html
且前面三個參數可以分別和full
做一個組合。
6.1 json
<code><span># curl http://www.ttlsa.com/status</span>
pool: www
process manager: dynamic
start time: <span>14</span>/May/<span>2014</span>:<span>22</span>:<span>40</span>:<span>15</span> +<span>0800</span>
start since: <span>58508</span>
accepted conn: <span>33</span>
listen queue: <span>0</span>
max listen queue: <span>8</span>
listen queue len: <span>0</span>
idle processes: <span>2</span>
active processes: <span>1</span>
total processes: <span>3</span>
max active processes: <span>5</span>
max children reached: <span>0</span>
slow requests: <span>2091</span></code>
<code># curl http://<span>127.0</span><span>.0</span><span>.1</span>/status?json
{"<span>pool</span>":<span><span>"www"</span></span>,"<span>process manager</span>":<span><span>"dynamic"</span></span>,"<span>start time</span>":<span><span>1400078415</span></span>,"<span>start since</span>":<span><span>59624</span></span>,"<span>accepted conn</span>":<span><span>27</span></span>,"<span>listen queue</span>":<span><span>0</span></span>,"<span>max listen queue</span>":<span><span>8</span></span>,"<span>listen queue len</span>":<span><span>0</span></span>,"<span>idle processes</span>":<span><span>2</span></span>,"<span>active processes</span>":<span><span>1</span></span>,"<span>total processes</span>":<span><span>3</span></span>,"<span>max active processes</span>":<span><span>5</span></span>,"<span>max children reached</span>":<span><span>0</span></span>,"<span>slow requests</span>":<span><span>2145</span></span>}</code>
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 - 上一個請求使用的記憶體
7.完成
php-fpm狀態頁非常使用,使用zabbix或nagios監控可以考慮使用xml或預設方式。用web的話,推薦使用html,表格會比較清晰。
以上就介紹了phpfpm使用自備的status優化步驟,包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。