繁体   English   中英

以JSON或XML格式输出的Apache“服务器状态”(mod_status)?

[英]Apache “server-status” (mod_status) output as in JSON or XML format?

Apache“ mod_status”:

我们知道,通过使用“ mod_status”,我们可以检查Apache的当前状态。 它返回很多信息,类似于此示例页面(由Apache提供)中的内容

https://www.apache.org/server-status

我需要做什么:

我需要解析然后处理此结果,尤其是ExtendedStatus标志(位于httpd.conf内部)给出的详细连接部分。 该部分看起来像:

Srv PID Acc M   CPU SS  Req Conn    Child   Slot    Client  VHost   Request
0-24    23433   0/94/338163 _   208.04  2   0   0.0 1.85    22068.75    221.254.46.37       
0-24    23433   0/99/337929 _   208.93  1   1141    0.0 2.23    19373.00    197.89.161.5        
0-24    23433   0/94/337834 _   206.04  4   0   0.0 3.46    22065.36    114.31.251.82       
0-24    23433   0/95/338139 _   198.94  2   7   0.0 2.74    21101.66    122.252.253.242     
0-24    23433   0/111/338215    _   206.21  3   0   0.0 3.89    19496.71    186.5.109.211

我的问题:

是否可以通过结构化数据格式(例如JSON)获取此页面(信息) (因为我需要通过PHP解析它们。之后再做一些其他工作。)

我不能只使用一些简单的方法,例如Javascript DOM解析器(例如:jQuery)。 因为我需要脚本在服务器的Linux命令行(本地)中运行。 不能通过外部任何高级客户端浏览器访问。

因此,通过Javascript(JQuery等)进行解析几乎不是一种选择。 我最好接收结构化数据。 所以我可以轻松地从PHP解析。 通过终端触发PHP脚本,例如:

# php /www/docroots/parse-server-status.php

或至少:

# curl -I http://localhost/parse-server-status.php

题:

  • 请问如何从Apache的服务器状态(mod_status)中获取JSON或XML?

谢谢大家

我认为没有办法在标准的Apache mod_status中获取json。 但是在开发人员列表上有关于此主题的讨论。

简而言之:您必须在服务器上安装其他脚本。 而且您需要在服务器上使用mod_lua。 这是项目页面:

https://github.com/Humbedooh/server-status

安装该lua脚本后,您可以获取json文件。 Daniel在这里安装了一个示例脚本:

HTML视图: http//httpd.apache.org/server-status
JSON: http//httpd.apache.org/server-status? view = json
扩展JSON: http : //httpd.apache.org/server-status? view= json& extended= true (很多数据:p)

在JavaScript / jQuery(ES6)中,我们可以使用?auto获取Apache机器的可读状态,并通过正则表达式解析内容:

$.get('http://localhost/parse-server-status.php?auto', (d) => {
  const o = {};
  const host = d.substring(0, d.indexOf('\n'));
  Array.from(d.replace(host, '').matchAll(/^([\w\s]+)\:\s(.*)+/gm)).forEach(l => o[l[1].replace(/\s/, '')] = l[2]);
  console.log(host, o);
});

控制台示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM