簡體   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