2
votes

Apache "mod_status":

We know, by using "mod_status", we can check Apache's current status. It returns a lot of information, something like in this sample page (provided by Apache):

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

What i need to do:

I need to parse and then process this results, especially the detailed connections section given by ExtendedStatus flag (inside httpd.conf). The section looks something like:

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

My Question:

Is it possible to get this page (information) via a structured data format, like JSON? (Because i need to parse them via PHP. And then do some further stuffs later.)

I cannot just use some easy ways, like Javascript DOM Parsers (like: jQuery). Because i need the script to be running in the Server's Linux Commandline (locally) itself. Not via any fancy client Browsers from outside.

So, parsing this via Javascript (JQuery, etc) is almost not a choice. I better receive a structured data. So i can parse from PHP way easily. Trigger the PHP Script via Terminal, like:

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

Or, at least:

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

Question:

  • Any idea how to get the JSON or XML out of Apache's Server Status (mod_status), please?

Thanks all.

2
The terse ?auto URL arg returns a plaintext summary that is fairly easy to parse. Try it: curl localhost:80/server-status?autoMarkHu

2 Answers

4
votes

I don't think there is a way to get json in the standard apache mod_status. But there was a discussion on the developer list about this topic.

In short: There is an other script that you have to install on your server. And you need mod_lua on the server. Here is the project page:

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

After installing that lua script, you could get the json files. Daniel installed a sample script here:

HTML view: http://httpd.apache.org/server-status
JSON: http://httpd.apache.org/server-status?view=json
Extended JSON: http://httpd.apache.org/server-status?view=json&extended=true (LOT OF DATA :p)

3
votes

In JavaScript/jQuery (ES6) we can get Apache machine readable status with ?auto and parse the content via Regular Expressions:

$.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);
});

Console example