服务器过载时的Apache2状态

如何检查apache2过载时的状态? 也就是说,当它不响应HTTP请求?

apache2ctl status基本上是状态页面上的wget 。 我需要一些可以在命令行中工作的东西而不需要这个页面。

我知道两种方法你可能会觉得有用:

1)mod_backdoor指定一个特殊的线程和侦听套接字,当所有的普通线程绑定时,允许你点击/服务器状态(应该在networkingsearch中很容易地find它)

http://people.apache.org/~trawick/mod_backdoor.txt http://people.apache.org/~trawick/mod_backdoor.c

2)perl可以parsingapache记分牌,如果你让它使用磁盘记分牌(ScoreBoardFile)

http://search.cpan.org/~opi/Apache2-ScoreBoardFile-0.01/lib/Apache2/ScoreBoardFile.pm

这是有适当的监测系统回报的情况之一。 它会收集你所有的数据,并会告诉你最后的已知数据,即使服务失败。 更不用说在资源池开始变空时得到警报的可能性,以便在服务中断之前采取行动。

当牛奶已经洒在地板上时,我猜想什么是相当好的解决办法。

安装适当的监控系统,或者玩bash:

 #!/bin/bash # WTF APACHE??? # cpu count CPU=$(cat /proc/cpuinfo | grep "^processor" | wc -l) # load average count LOAD_5=$(cat /proc/loadavg | awk '{print $2}') LOAD_AVERAGE_5=$(($(echo ${LOAD_5} | awk '{print 100 * $1}') / ${CPU})) # Red Alert : 85% high load 5 min # send some mail with status if [ ${LOAD_AVERAGE_5} -ge 85 ] ; then httpd status > /tmp/apache_status.log mail -s "APACHE STATUS" [email protected] < /tmp/apache_status.log service httpd stop else [ ${LOAD_AVERAGE_5} -le 50 ] ; then if ps aux | grep [h]ttpd; then echo 'OK'; else service httpd start; fi fi 

有趣的问题,但我相信你不能。 一个解决方法可能会杀死一些apache的线程,并确保你是第一个连接到新产生的进程,以显示Apache的状态。

编辑:是的,让我们玩bash

通过拉动你的Apache服务器状态页面的记分板,让你定义何时作出反应,下面的工作。

使用_f_custom()函数。 我已经build立了两个例子:

  1. 如果发送应答模式中有超过150个进程,您将收到一封电子邮件
  2. 如果有less于20个空位,也会发送电子邮件。

`

 #!/bin/bash _sleep="5" _f_getfullstatus() { curl $_uri 2> /dev/null } _f_mailto() { ( echo -e "To:$1\nFrom:$1\nSubject:${2}:\n\n${3} ${4}" ; _f_getfullstatus ) | sendmail -t } _f_custom() { case "$1" in _) ;; S) ;; W) if [[ $2 -gt 150 ]] ; then _f_mailto $_email "Houson, we've got a problem" "Currently there are $2 processes in "sending reply" mode" ; fi ;; K) ;; D) ;; L) ;; G) ;; I) ;; .) if [[ $2 -lt 20 ]] ; then _f_mailto $_email "Running out of open slots" "there are only $2 available atm" ; fi ;; esac } _f_count() { for _status in _ SRWKDCLGI \. do _counter=$(echo $_auto_output | sed "s/[^$_status]//g" | wc -m) if [[ $_verbose == "yes" ]] ; then echo -n "Status of key ${_status}:" echo $_counter fi _f_custom $_status $_counter done } while [[ $# > 0 ]] ; do _opt="$1" case $_opt in -u) shift _uri="$1" ;; -m) shift _email="$1" ;; -s) shift _sleep="$1" ;; -D) _daemon="yes" ;; -v) _verbose="yes" ;; esac shift done _auto_output=$(curl ${_uri}?auto 2> /dev/null | tail -1 | sed 's/Scoreboard: //g') if [[ $_daemon == "yes" ]] ; then while true ; do _f_count sleep $_sleep done else _f_count fi 

这需要$PATH sendmailcurl

as –help没有实现:

-u: URI to server-status page -m: sets a emailaddress to send your errors to -v: let it run verbosly -D: let it run in w while true loop (daemonize) -s: interval in seconds between status requests