我們平時(shí)使用 Apache 常常了解它的性能只能使用 “ps aux|grep httpd|wc -l” 查看有多少個(gè)進(jìn)程,但處理了多少 http 的請求我們不清楚,進(jìn)程是不是在工作,還是在等都不是很明白,要了解 Apache 的性能,我們需要使用 Apache Server Status 的模塊來(lái)詳細了解 Apache 工作的怎么樣。下面我來(lái)介紹使用 Cacti 來(lái)監控它。
在 httpd.conf 文件中加入如下內容:
LoadModule status_module modules/mod_status.so
ExtendedStatus On<location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 10.1.2.24
</location>
打開(kāi)查看的話(huà)就使用 http://localhost/server-status 來(lái)訪(fǎng)問(wèn)。
注意:上面的鏈接還可以加個(gè) “?refresh=N” 來(lái)設置多久自動(dòng)刷新一次。
目前最新版本的 Apache 中 mod_status 是內置的,這應該跟我在編譯時(shí)加入的 “–enable-so” 選項有關(guān)。
如果你的 Apache 中沒(méi)有 mod_status 模塊,甚至沒(méi)有動(dòng)態(tài)鏈接庫 .so 文件,那么請使用如下命令進(jìn)行安裝:
% /path/to/apache/bin/apxs -cia mod_status.c
-cia 選項表示編譯(compile)、安裝(install)及啟動(dòng) (activate)。第一個(gè)功能很清楚;安裝表示將 .so文件放到Apache 可找到的位置;而啟用則表示將模塊加入 httpd.conf 文件中。
我的機器的顯示如下:
Apache Server Status for 10.10.6.201
Server Version: Apache/2.2.17 (Unix) PHP/5.3.5
Server Built: Mar 17 2011 11:07:46——————————————————————————–
Current Time: Thursday, 31-Mar-2011 13:57:04 CST
Restart Time: Tuesday, 29-Mar-2011 14:22:34 CST
Parent Server Generation: 6
Server uptime: 1 day 23 hours 34 minutes 30 seconds
Total accesses: 30867 – Total Traffic: 62.1 MB
CPU Usage: u6.14 s.56 cu5.21 cs0 – .00695% CPU load
.18 requests/sec – 380 B/second – 2111 B/request
1 requests currently being processed, 9 idle workers
_W._.____…__._…………………………………………
……………………………………………………….
……………………………………………………….
……………………………………………………….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 processSrv PID Acc M CPU SS Req Conn Child Slot Client VHost Request
0-6 30955 0/63/1766 _ 0.52 46 0 0.0 0.07 3.36 10.1.2.24 10.10.6.201 GET /cacti/images/graph_zoom.gif HTTP/1.1
1-6 31270 1/39/1612 W 0.87 0 0 6.6 0.14 3.70 10.1.2.24 10.10.6.201 GET /server-status HTTP/1.1
2-6 – 0/0/1802 . 0.00 45 0 0.0 0.00 3.45 ::1 10.10.6.201 OPTIONS * HTTP/1.0
3-6 31274 0/62/2113 _ 1.34 46 211 0.0 0.23 4.12 10.1.2.24 10.10.6.201 GET /cacti/graph_image.php?local_graph_id=118&rra_id=0&view_typ
4-6 – 0/0/1526 . 0.00 44 0 0.0 0.00 2.79 ::1 10.10.6.201 OPTIONS * HTTP/1.0
5-6 31343 0/24/1762 _ 0.70 46 138 0.0 0.09 3.19 10.1.2.24 10.10.6.201 GET /cacti/graph_image.php?local_graph_id=116&rra_id=0&view_typ
6-6 31344 0/31/1979 _ 0.29 46 0 0.0 0.06 4.19 10.1.2.24 10.10.6.201 GET /cacti/images/graph_properties.gif HTTP/1.1
7-6 31280 0/48/2123 _ 1.40 46 0 0.0 0.22 4.40 10.1.2.24 10.10.6.201 GET /cacti/plugins/thold/images/reddot.png HTTP/1.1
8-6 31281 0/43/1558 _ 1.02 46 235 0.0 0.14 3.52 10.1.2.24 10.10.6.201 GET /cacti/graph_image.php?local_graph_id=117&rra_id=0&view_typ
9-6 – 0/0/2015 . 0.00 43 0 0.0 0.00 3.64 ::1 10.10.6.201 OPTIONS * HTTP/1.0
10-6 – 0/0/1614 . 0.00 42 0 0.0 0.00 2.92 ::1 10.10.6.201 OPTIONS * HTTP/1.0
11-6 – 0/0/1665 . 0.00 41 0 0.0 0.00 3.56 ::1 10.10.6.201 OPTIONS * HTTP/1.0
12-6 31347 0/34/1862 _ 0.42 46 0 0.0 0.06 4.17 10.1.2.24 10.10.6.201 GET /cacti/plugins/thold/images/edit_object.png HTTP/1.1
13-6 31282 0/55/1899 _ 0.98 46 0 0.0 0.13 3.46 10.1.2.24 10.10.6.201 GET /cacti/images/graph_page_top.gif HTTP/1.1
14-6 – 0/0/1690 . 0.00 40 0 0.0 0.00 3.76 ::1 10.10.6.201 OPTIONS * HTTP/1.0
15-6 31283 0/55/1714 _ 0.83 46 0 0.0 0.15 3.65 10.1.2.24 10.10.6.201 GET /cacti/images/graph_query.png HTTP/1.1
16-6 – 0/0/1792 . 0.00 39 0 0.0 0.00 3.40 ::1 10.10.6.201 OPTIONS * HTTP/1.0
17-6 – 0/0/375 . 4.25 1339 0 0.0 0.00 0.87 ::1 10.10.6.201 OPTIONS * HTTP/1.0——————————————————————————–
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 的輸出中每個(gè)字段所代表的意義如下:
接下來(lái)是所有 Apache 進(jìn)程的狀態(tài),每一個(gè)字符表示一個(gè)程序,最多可以顯示 256 個(gè)程序的狀態(tài)。
以下為每一個(gè) Scoreboard Key 所表示的意義:


聯(lián)系客服