AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 712998
Accepted
Raptor
Raptor
Asked: 2015-08-10 18:50:35 +0800 CST2015-08-10 18:50:35 +0800 CST 2015-08-10 18:50:35 +0800 CST

Apache 服务器状态页面是否有可用的过滤器?

  • 772

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

是否有任何调整、选项或标志来隐藏这些OPTIONS过程?

apache-2.2
  • 1 1 个回答
  • 2389 Views

1 个回答

  • Voted
  1. Best Answer
    Damiano Verzulli
    2015-08-11T12:29:20+08:002015-08-11T12:29:20+08:00

    除了重新编译mod_status以满足您的需要(这可能听起来有点矫枉过正,但......它仍然可行),mod_status提供了一个专门为机器可读处理设计的选项。根据官方文档:

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

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

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

    由于听起来有点奇怪,我检查了mod_status模块的源代码。除了附加且未记录的“?notable”选项外,“ apache2-2.2.22/modules/generators/mod_status.c ”(我的 Ubuntu 12.04 LTS 笔记本)中的源代码包括:

     * /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
    

    (顺便说一句:我发现阅读“?notable - 返回不支持表格的浏览器的页面”既有趣又好奇,因为我太老了/太古老了记得网络的早期,表格支持是可用浏览器的新功能!)

    我还检查了“?auto”格式中缺少的进程列表是一个设计特性:

    #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 进程? ”,我的回答是,您唯一的选择是“调整”一个小应用程序:

    1. 与/server-status标准 URL相比,它的作用类似于 HTTP 客户端;
    2. 解析结果以从 processlist 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 行。

    请注意,上述应用程序缺乏基本的错误处理,所以....如果出现问题,请不要怪我:-)

    • 11

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve