開啓Apache的server-status

        最近常常發現一臺 Apache 服務器監控報警,登錄服務器後發現 Apache 的進程佔用過多的服務器資源而致使沒法響應,查看 Apache 的日誌,太龐雜又無法直觀的看出問題來。還好 Apache 自帶的 server-status 功能能夠很好解決問題。
要啓用 server-status 必須首先加載 server-status 模塊,你能夠用如下命令查看是否已經加載了模塊:linux

 # /usr/local/apache/bin/httpd -l | grep mod_status.c

若是沒有安裝這個模塊,那麼就須要您從新編譯這個模塊了,進入 apache 的源碼目錄:apache

# cd /usr/local/src/httpd-2.2.14/modules/generators
# /usr/local/apache/bin/apxs -cia mod_status.c 

這樣模塊就編譯好了。你查看一下 apache 的配置文件裏已經增長了
LoadModule status_module      modules/mod_status.so
 服務器

啓動 server-status 功能,在 apache 的配置文件中增長一下配置代碼:dom

 ExtendedStatus On
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from IP
</Location>

打開查看的話就使用http://IP/server-status來訪問,若是須要自動更新,能夠用
http://IP/server-status?refresh=N,N是更新時間,默認是秒。ide

下面是個人服務器的server-status顯示:ui

Apache Server Status for xxx.xxx.xxx.xxx
Server Version: Apache/2.2.14 (Unix) PHP/4.4.9
Server Built: May 31 2010 10:31:44
this

Current Time: Thursday, 16-Sep-2010 15:57:34 CST
Restart Time: Monday, 13-Sep-2010 09:17:00 CST
Parent Server Generation: 5
Server uptime: 3 days 6 hours 40 minutes 33 seconds
Total accesses: 3303 - Total Traffic: 12.5 MB
CPU Usage: u.53 s.17 cu0 cs0 - .000247% CPU load
.0117 requests/sec - 46 B/second - 3958 B/request
1 requests currently being processed, 5 idle workers
__W___..........................................................
................................................................
................................................................
................................................................
spa

Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
firefox

Srv PID Acc M CPU  SS Req Conn Child Slot Client VHost Request
0-5 16798 0/552/552 W  0.12 0 0 0.0 2.08 2.08  xxx.xxx.xxx.xxx localhost.localdomain GET /status HTTP/1.1
1-5 16799 0/551/551 _  0.12 16347 0 0.0 2.08 2.08  xxx.xxx.xxx.xxx localhost.localdomain GET /status?refresh=5 HTTP/1.1
2-5 16800 0/551/551 _  0.11 15680 0 0.0 2.08 2.08  xxx.xxx.xxx.xxx localhost.localdomain GET /status HTTP/1.1
3-5 16801 0/566/566 _  1.14 11517 0 0.0 2.10 2.10  xxx.xxx.xxx.xxx localhost.localdomain GET /awstatsicons/browser/firefox.png HTTP/1.1
4-5 16802 0/563/563 _  0.65 11517 0 0.0 2.15 2.15  xxx.xxx.xxx.xxx localhost.localdomain GET /awstatsicons/browser/msie.png HTTP/1.1
5-5 16803 0/560/560 _  0.13 11517 0 0.0 2.08 2.08  xxx.xxx.xxx.xxx localhost.localdomain GET /awstatsicons/os/linux.png HTTP/1.1
日誌

Srv Child Server number - generation
PID OS process ID
Acc Number of accesses this connection / this child / this slot
M Mode of operation
CPU CPU usage, number of seconds
SS Seconds since beginning of most recent request
Req Milliseconds required to process most recent request
Conn Kilobytes transferred this connection
Child Megabytes transferred this child
Slot Total megabytes transferred this slot

server-status 的輸出中每一個字段所表明的意義以下:
字段         說明
Server Version         Apache 服務器的版本。
Server Built         Apache 服務器編譯安裝的時間。
Current Time         目前的系統時間。
Restart Time         Apache 從新啓動的時間。
Parent Server Generation         Apache 父程序 (parent process) 的世代編號,就是 httpd 接收到 SIGHUP 而從新啓動的次數。
Server uptime         Apache 啓動後到如今通過的時間。
Total accesses         到目前爲此 Apache 接收的聯機數量及傳輸的數據量。
CPU Usage         目前 CPU 的使用情形。
_SWSS….         全部 Apache process 目前的狀態。每個字符表示一個程序,最多能夠顯示 256 個程序的狀態。
Scoreboard Key         上述狀態的說明。如下爲每個字符符號所表示的意義:

    * _:等待連結中。
    * S:啓動中。
    * R: 正在讀取要求。
    * W:正在送出迴應。
    * K:處於保持聯機的狀態。
    * D:正在查找 DNS。
    * C:正在關閉連結。
    * L:正在寫入記錄文件。
    * G:進入正常結束程序中。
    * I:處理閒置。
    * .:尚無此程序。

Srv         本程序與其父程序的世代編號。
PID         本程序的 process id。
Acc         分別表示本次聯機、本程序所處理的存取次數。
M         該程序目前的狀態。
CPU         該程序所耗用的 CPU 資源。
SS         距離上次處理要求的時間。
Req         最後一次處理要求所耗費的時間,以千分之一秒爲單位。
Conn         本次聯機所傳送的數據量。
Child         由該子程序所傳送的數據量。
Slot         由該 Slot 所傳送的數據量。
Client         客戶端的地址。
VHost         屬於哪個虛擬主機或本主機的 IP。
Request         聯機所提出的要求信息。

不錯吧,挺直觀的吧。

相關文章
相關標籤/搜索