您的位置:首页 > 运维架构 > Apache

开启Apache的server-status

2010-09-16 20:34 633 查看
最近经常发现一台 Apache 服务器监控报警,登陆服务器后发现 Apache 的进程占用过多的服务器资源而导致无法响应,查看 Apache 的日志,太庞杂又没法直观的看出问题来。还好 Apache 自带的 server-status 功能可以很好解决问题。

要启用 server-status 必须首先加载 server-status 模块,你可以用以下命令查看是否已经加载了模块:

# /usr/local/apache/bin/httpd -l | grep mod_status.c
如果没有安装这个模块,那么就需要您重新编译这个模块了,进入 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 的配置文件中增加一下配置代码:

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是更新时间,默认是秒。

下面是我的服务器的server-status显示:

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

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___..........................................................

................................................................

................................................................

................................................................

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-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 联机所提出的要求信息。

不错吧,挺直观的吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  职场 apache 休闲