回到他孔老夫子传授维基百科的本页

发表日子 2011-09-26 12:10:28
最后修正 2020-12-07 23:25:24
作者 王博士

维基目录

Description

apache-top.py monitors the apache server process status in a real time way.

apache-top.py is a Python script initially written by Carles Amigó fr3nd.net on 2006. Which is in its turn improved by Mark of iSartor Wiki on 2012. This version is again another improvement, as I found some defects in the old scripts as I used them.

Apache-top shows apache server process status at a real time, similar to the unix/linux top command (native C), apachetop (Native C) for apache server log analysis, and mytop (Perl) for MySQL Database server real-time status.

apache-top.py is really in the real time mode, as the process status is directly produced by the core apache server executable, not by the post analysis of the web server access log files. This permits it of having a different usage from the Perl apachetop script, as the later cannot see the running processes of apache server. With apache-top.py, you can see which is the process that is blocking your server, overloading the CPU, and exhausting your RAM... You can eventually kill the process to save your server... and improve the error web page that overheats your server. This cannot be done by the already excellent apachetop Perl script, as apachetop behaves after the server, not at the same time as does apache-top.py.

Synopsis

# apache-top.py [-d time_in_s] -u http://www.domain.tld/server-status

Shell Command Examples

Requirements

What apache-top can do for you?

You have a web apache server, with apache-top you can get:

  1. The active apache processes with their associated PID, the status, the seconds being active, the CPU usage, the asociated VirtualHost, the accessing ip and the request (POST or GET, the file being accessed and the used protocol).
  2. The server uptime and the last time it was restarted.
  3. The CPU usage.
  4. Requests by second, Kb by second and the average Kb by request.
  5. Number of active and inactive processes.
  6. A graph with the inactive and active processes and their status.

View the Code

Download the current python script

Improvements

Why add another version of apache-top.py? I found one major defect in the old versions. The Monitoring process is constantly interrupted when the server is busy, or some apache process is interrupted by the system control. One must constantly launch the apache-top.py. As the modified script does a good job for me, I would like to share this with other users. Compared to the above two versions, I bring these improvements:

  1. As apache-top makes a HTTP query to the apache server at each refreshing, it may be costful if the frequency is too large. To control the refreshing cadence, I added -d time command option, you can now input directly the interval delay from the shell command prompt for status refreshing.
  2. For the coherence with the shell prompt option flag -d time, sorry Dear Mark, I've replaced the s interactive command by d, similar to the new apachetop command, to dynamically change the interval delay.
  3. Add h interactive command in order to show a help screen, just as does the top command.
  4. Replaced urllib.urlopen() by urllib2.urlopen(), in order to specify URL opening timeout, avoiding the infinite looping when the user type a nonexistent, or temporarily unavailable server URL.
  5. Modified the class method ApacheStatusParser.handle_entityref(), so in screen mode, URL arguments separator is correctly shown as & but not & as before, ie, /mydancer.php?name=Carolina&sex=f, instead of /mydancer.php?name=Carolina&sex=f.
  6. Bypassing the HTML parsing error, but raising the URL error exception urllib2.URLError at the first remote access in order to invalidate the existence of the specified URL to be monitored. Even for a valid URL, an apache server may sometimes output erroneous HTML string. In the old versions, the monitoring will be interrupted because of HTMLParser error with this error message:
    ERROR parsing the data. Please, make sure you are alowed to read the server-status page and you have ExtendedStatus flag activated.
    This point is useful for a very busy web server, as this is often the case when one makes use of apache-top. Accurately, http://www.domain.tld/server-status can often output incomplete HTML string because of the blocking of the server by other processes so HTMLParser cannot parse the string correctly in time. This aborted very often the monitoring process. With the modification, the monitor will simply pass this turn, and will refresh the screen only when the next good information is received. It can work for days and days only if you type the interactive command q, [ESC] or Ctrl+C to quit.
  7. Added the interactive command k to kill a PID just like apachetop does. This works only if apache-top.py is launched on the localhost of the monitored server.
  8. Added trace possibility for the both PID like 12345 and IP like 192.168.1.1 in order to locate PID or IP that causes your apache server overloading.
  9. Use arrow keys ←↑↓→ to select to trace/untrace PID or IP.
  10. Added the interactive command f to filter URL using a Regex just like apachetop does.
  11. Added the interactive command n to toggle key to use name servers to show visiting IPs or Hostnames just like iftop does. But you'd better rarely use it to save your server resource.

Commands

    Usage: apache-top.py [-d delay] -u url
        -u url    Url where apache-status is located
                  Example: apache-top.py -u http://www.domain.com/server-status
        -d delay  Refreshing delay in s


    Interactive keys:
        a       Switch between show all processes and show only active processes (default)
        C       Sort by CPU usage
        d       Change interval delay in s
        f       Filter/Unfilter URL Regex
        h or ?  Toggle this help window
        I       Sort by IP
        k       Kill a process to be input by the user on the keyboard
        M       Sort by Mode of operation
        n       Toggle key to use name servers to show visiting IPs or Hostnames
        P       Sort by PID
        p       Pause/Unpause display (freeze/free screen updates)
        q       Exit
        R       Sort by Request
        r       Reverse sort
        S       Sort by Seconds since beginning of most recent request
        t       Trace/untrace a single PID or IP to be input by the user on the keyboard
        V       Sort by VirtualHost

Use DOWN and UP arrow keys to move the star * sign. LEFT to trace the active PID, RIGHT its IP.

Screen Shots

We select some screen shots to illustrate this command line tool for webmaster:

Notice

One may remark that the apache2 mod-status, or mod_status.c may be in error when it gives a 6.25% CPU Load. Since my top command shows a load of 6.25 at the same time without the percent sign. At the nearest time I've verified http://www.domain.tld/server-status with IE, Google Chrome and Firefox navigators, the percent sign remains without a change of 100 times in values. So this error is not attributable to the apache-top.py command, but due to the apache server::Mod_Status itself. We willingly don't correct it in apache-top.py on a holp of a future update of mod_status.c.

License

Apache-top uses GNU/GPL License, to the original author Carles Amigó.

如果您需要更多的信息,请来电与我们联系。

文章链接产品 | 文章产品链接 | 我肯切地等待您的反馈...
您的朋友 王博士

jin货币 | zhong钟表 | yi翻译 | ci词典 | xie书写 | zhuan字码转换

提供反馈意见 (1)

电子信箱 网站地址

请在空格里打入以下安全字符串:
拷贝字符串。

亚洲之家 > 维基 > 维基目录 | 基本销售条款 | 退换和还款 | 保密条款 | 常问问答
  

想来吗? | 请7/7电话联系00 33 467 790 487 (电话)

节日    关闭
恭喜1918年一战停战节: 明天星期一 十一月十一日, ,您的亚洲之家将在9:00到0点之间营业,勿忘光临啊! 作息时间表
 
爆起窗口    关闭
请耐心等待内容的到来...