有没有可用于Apache服务器状态页面的filter?

我通过mod_status模块启用了Apache状态页面。 进程列表很长,其中大部分是OPTIONS * HTTP/1.0 ,我想过滤掉。

有没有任何调整,选项或标志来隐藏这些OPTIONS进程?

除了重新编译mod_status来满足你的需要(这可能听起来有些过分,但是……仍然可行), mod_status提供了一个专门为机器可读处理devise的选项。 根据官方文件 :

状态文件的机器可读版本可通过访问http://your.server.name/server-status?auto页面来获得。 这在自动运行时很有用[….]

因此,捕获mod_status的输出就像包含对wget , curl或任何其他http客户端库的调用一样简单,可以启动/包含在您的应用程序中,以满足您的需求。

不幸的是,我刚刚发现使用“?auto”格式时, ExtendedStatus指令提供的大部分附加信息都不显示! 这意味着使用“?auto”选项,您无法访问进程列表。

听起来有点奇怪,我检查了mod_status模块的源代码。 除了另外一个没有logging的“?notable”选项,我的Ubuntu 12.04 LTS笔记本的“ apache2-2.2.22 / modules / generators / mod_status.c ”中的源代码包括:

  * /server-status - Returns page using tables * /server-status?notable - Returns page for browsers without table support * /server-status?refresh - Returns page with 1 second refresh * /server-status?refresh=6 - Returns page with refresh every 6 seconds * /server-status?auto - Returns page with data for automatic parsing 

(顺便说一句:我觉得既有趣又好奇的阅读“?显着 – 浏览器返回页面没有表支持”,因为我很古老/记得早期的networking,表支持是可用浏览器的function!)

我还检查了“?auto”格式中缺less的进程列表是一个辅助function:

 #define STAT_OPT_AUTO 2 [...] static const struct stat_opt status_options[] = { {STAT_OPT_REFRESH, "refresh", "Refresh"}, {STAT_OPT_NOTABLE, "notable", NULL}, {STAT_OPT_AUTO, "auto", NULL}, {STAT_OPT_END, NULL, NULL} }; [...] if (r->args) { [...] case STAT_OPT_AUTO: ap_set_content_type(r, "text/plain; charset=ISO-8859-1"); short_report = 1; break; [...] if (short_report) ap_rputs("\n", r); else { ap_rputs("</pre>\n", r); ap_rputs("<p>Scoreboard Key:<br />\n", r); [...lots of other things, including "processlist"...] } [...] 

正如你所看到的,你需要的是在最后一个“if”的“else”部分。 因此,它不包含在“?auto”格式中,因为在这种情况下,我们属于“short_report”的情况。

所以,在上面的所有回到你的问题:“ 是否有任何调整,选项或标志来隐藏这些OPTIONS过程? ”,我的答案是,你唯一的select是“调整”一个小应用程序,

  1. 像HTTP客户端对比/服务器状态标准URL;
  2. parsing结果以从stream程列表HTML表中提取数据;
  3. 跳过与OPTION请求相关的表行;
  4. 做任何你需要的其他行。

因为我对PERL感到满意,并且对HTML :: TableExtract模块有一些好运,所以可以使用的基础如下:

 #!/usr/bin/perl use strict; use HTML::TableExtract; # PATH to "curl" utility my $CURL = "/usr/bin/curl"; # URL of the server-status we want to process my $STATUS_URL = "http://localhost/server-status"; # those are the headers in the first row of the table we want to extract # Used by HTML::TableExtract to search for our table, within the whole HTML output my $headers =['Srv','PID','Acc','M','CPU','SS','Req','Conn','Child','Slot','Client','VHost','Request']; # Let's fetch the status page... my $output = `$CURL -s $STATUS_URL`; # Let's search for our table within the HTML... my $tables = HTML::TableExtract->new( headers => $headers ); # We found it (hopefully), so let's parse it... $tables->parse($output); # ...and let's stick to the first one my $status_table = $tables->first_table_found; # Now let's loop allover the rows... foreach my $row_ref ($status_table->rows) { # Let's de-reference the ARRAY reference, so to better manager # the various elements... my @row = @$row_ref; # Let's check for an OPTIONS row... if ($row[12]=~/OPTIONS/) { # simply skip to next row in the loop next; } # Let's choose whatever columns we want (first column has index "0") # So here we have Srv, PID, Client and Request foreach my $column (0,1,10,12) { print $row[$column]."|"; } print "\n"; } 

在我的情况下,上面的脚本产生以下输出:

 verzulli@tablet-damiano:~$ perl elab.pl 0-1|9183|127.0.0.1|GET /server-status HTTP/1.1| 1-1|9184|127.0.0.1|GET /server-status HTTP/1.1| 2-1|9185|127.0.0.1|GET /server-status HTTP/1.1| 3-1|9186|127.0.0.1|GET /server-status HTTP/1.1| 4-1|9187|127.0.0.1|GET /server-status HTTP/1.1| 5-1|9188|127.0.0.1|GET /server-status HTTP/1.1| 

你可以看到,跳过OPTIONS行。

请注意,上面的应用程序缺乏基本的error handling,所以….不要怪我,如果事情会出错:-)