诛仙昆仑仙境六怪点:在 Cacti 下实现对 Apache 的监控

来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 12:01:35

我们平时使用 Apache 常常了解它的性能只能使用 “ps aux|grep httpd|wc -l” 查看有多少个进程,但处理了多少 http 的请求我们不清楚,进程是不是在工作,还是在等都不是很明白,要了解 Apache 的性能,我们需要使用 Apache Server Status 的模块来详细了解 Apache 工作的怎么样。下面我来介绍使用 Cacti 来监控它。

1.Apache Server Status 模块的启用:

在 httpd.conf 文件中加入如下内容:

LoadModule status_module modules/mod_status.so
ExtendedStatus On


SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 10.1.2.24

打开查看的话就使用 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 process

Srv 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 的输出中每个字段所代表的意义如下:

  • 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 的使用情形。

接下来是所有 Apache 进程的状态,每一个字符表示一个程序,最多可以显示 256 个程序的状态。

以下为每一个 Scoreboard Key 所表示的意义:

  • * _:等待连结中。
  • * S:启动中。
  • * R: 正在读取要求。
  • * W:正在送出回应。
  • * K:处于保持联机的状态。
  • * D:正在查找 DNS。
  • * C:正在关闭连结。
  • * L:正在写入记录文件。
  • * G:进入正常结束程序中。
  • * I:处理闲置。
  • * .:尚无此程序。
2.在 Cacti 中实现对 Apache 的监控:
  1. 下载 模板和脚本.
  2. 解压缩下载的 ApacheStats_0.8.2.zip 文件,一共有二个文件,一个处理脚本php的,另一个是xml的文件.
  3. 其中的 ss_apache_stats.php 是脚本文件,它是一个php的文件,放到你的cacti/scripts/下面.
  4. 在 Cacti 界面导入 cacti_host_template_webserver_-_apache.xml 这个文件.
  5. 在 Cacti 中设置一些 Graph 即可。