我们平时使用 Apache 常常了解它的性能只能使用 “ps aux|grep httpd|wc -l” 查看有多少个进程,但处理了多少 http 的请求我们不清楚,进程是不是在工作,还是在等都不是很明白,要了解 Apache 的性能,我们需要使用 Apache Server Status 的模块来详细了解 Apache 工作的怎么样。下面我来介绍使用 Cacti 来监控它。
在 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>
打开查看的话就使用 http://localhost/server-status 来访问。
注意:上面的链接还可以加个 “?refresh=N” 来设置多久自动刷新一次。
目前最新版本的 Apache 中 mod_status 是内置的,这应该跟我在编译时加入的 “–enable-so” 选项有关。
如果你的 Apache 中没有 mod_status 模块,甚至没有动态链接库 .so 文件,那么请使用如下命令进行安装:
% /path/to/apache/bin/apxs -cia mod_status.c
-cia 选项表示编译(compile)、安装(install)及启动 (activate)。第一个功能很清楚;安装表示将 .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 的输出中每个字段所代表的意义如下:
接下来是所有 Apache 进程的状态,每一个字符表示一个程序,最多可以显示 256 个程序的状态。
以下为每一个 Scoreboard Key 所表示的意义:
联系客服