自定义乘客状态输出

问题描述 投票:0回答:1

我们有一台服务器在运行 Passenger 5.0.30 在...中 Ubuntu 12.04 服务器,当我们运行 sudo passenger-status 我们得到非常有用和简洁的信息。要获得更多信息,有一个选项 sudo passenger-status --show=requests 但这些信息太多,无法快速识别某些请求甚至服务器的问题。

有什么办法可以将这些信息包含在 sudo passenger-status 输出每个进程正在进行的当前操作?如果没有,有什么想法或建议可以创建一个命令来解析这些信息并输出我需要的信息吗?

例子 sudo passenger-status 的输出。

Version : 5.0.30                      1
Date    : 2015-07-06 12:18:38 +0200   2
Instance: bdVuBLEf (nginx/1.8.0 Phusion_Passenger/5.0.13)

----------- General information -----------
Max pool size : 9                 3
App groups    : 2                 4
Processes     : 3
Requests in top-level queue : 0   5

----------- Application groups -----------
/var/www/phusion_blog/current/public:
  App root: /var/www/phusion_blog/current
  Requests in queue: 0
  * PID: 18334   Sessions: 0       Processed: 4595    Uptime: 5h 53m 29s
    CPU: 0%      Memory  : 99M     Last used: 4s ago
  * PID: 18339   Sessions: 0       Processed: 2873    Uptime: 5h 53m 26s
    CPU: 0%      Memory  : 96M     Last used: 29s ago

例子: sudo passenger-status --show=requests 输出(我特别想知道的是 path 属性)。)

{
   "threads" : 2,
   "thread1" : {
      "active_client_count" : 1,
      "active_clients" : {
         "2-2315" : {
            "connected_at" : {
               "local" : "Mon Jul  6 13:19:13 2015",
               "relative" : "0s ago",
               "timestamp" : 1436181553.120679
            },
            "connection_state" : "ACTIVE",
            "current_request" : {
               "app_response_http_state" : "PARSING_HEADERS",
               "app_sink_state" : {
                  "callback_in_progress" : false,
                  "initialized" : true,
                  "io_watcher_active" : false
               },
               "app_source_state" : {
                  "callback_in_progress" : false,
                  "initialized" : true,
                  "io_watcher_active" : true
               },
               "flags" : {
                  "dechunk_response" : true,
                  "https" : true,
                  "request_body_buffering" : false
               },
               "host" : "blog.phusion.nl",
               "http_major" : 1,
               "http_minor" : 1,
               "http_state" : "COMPLETE",
               "method" : "GET",
               "path" : "/",
               "refcount" : 1,
               "request_body_already_read" : 0,
               "request_body_fully_read" : true,
               "request_body_type" : "NO_BODY",
               "response_begun" : false,
               "session" : {
                  "gupid" : "16d1dbc-9VEXQm82is",
                  "pid" : 18334
               },
               "session_checkout_try" : 1,
               "started_at" : {
                  "local" : "Mon Jul  6 13:19:13 2015",
                  "relative" : "0s ago",
                  "timestamp" : 1436181553.121373
               },
               "state" : "WAITING_FOR_APP_OUTPUT",
               "sticky_session" : false,
               "want_keep_alive" : false
            },
            "lingering_request_count" : 0,
            "name" : "2-2315",
            "number" : 2315,
            "output_channel_state" : {
               "bytes_buffered" : {
                  "bytes" : 0,
                  "human_readable" : "0 bytes"
               },
               "callback_in_progress" : false,
               "mode" : "IN_MEMORY_MODE",
               "nbuffers" : 0,
               "reader_state" : "RS_INACTIVE"
            },
            "refcount" : 2,
            "requests_begun" : 1
         }
      },
      "disconnected_client_count" : 0,
      "disconnected_clients" : {},
      "free_client_count" : 127,
      "free_request_count" : 3,
      "mbuf_pool" : {
         "active_blocks" : 4,
         "active_memory" : {
            "bytes" : 2048,
            "human_readable" : "2.0 KB"
         },
         "chunk_size" : 512,
         "free_blocks" : 10,
         "offset" : 448,
         "spare_memory" : {
            "bytes" : 5120,
            "human_readable" : "5.0 KB"
         }
      },
      "pid" : 5171,
      "server_state" : "ACTIVE",
      "total_bytes_consumed" : 9209549,
      "total_clients_accepted" : 2315,
      "total_requests_begun" : 2315,
      "turbocaching" : {
         "fetches" : 1,
         "hit_ratio" : 0.0,
         "hits" : 0,
         "store_success_ratio" : null,
         "store_successes" : 0,
         "stores" : 1
      }
   },
   "thread2": {
      ...
   }
}
passenger ubuntu-12.04
1个回答
0
投票

如果你对python很熟悉(或者即使你不熟悉),你可以做以下操作。


import os
import json
import types

stream = os.popen("/path/to/passenger/directory/passenger-status --show=requests")
output = stream.read()
index_of_json_string_opening = output.find("{")
string_json = output[index_of_json_string_opening:]
requests_data = json.loads(string_json)

# for all threads
for thread in requests_data.keys():
  if isinstance(requests_data[thread], dict):
    # if there are active clients,
    if requests_data[thread]['active_client_count'] > 0:
      for active_client in requests_data[thread]['active_clients']:
        # get the data about the individual active clients & retrieve the current_request data
        current_request = requests_data[thread]['active_clients'][active_client]['current_request']

        # retrieve the path
        path = current_request['path']

        started_at = current_request['started_at']['local']

        # check if the session exists, i.e. if any thread is currently processing this, then the PID shall exist
        if 'session' in current_request:
          pid = current_request['session']['pid']
        else:
          pid = "NOT FOUND"

        print("PATH : " + str(path))
        print("PID : " + str(pid))
        print("Started at : " + str(started_at))
        print("\n")

输出的方式如下。

PATH : /some/path/here
PID : 50415
Started at : Thu Apr 23 15:19:34 2020


PATH : /some/path/here
PID : 50422
Started at : Thu Apr 23 15:19:34 2020


PATH : /some/path/here
PID : NOT FOUND
Started at : Thu Apr 23 15:19:34 2020

同样,你也可以检索requestthread的其他重要参数。

参考 https:/www.phusionpassenger.comlibraryadminstandaloneoverall_status_report.html 为更多的了解 --show=requests 输出。

© www.soinside.com 2019 - 2024. All rights reserved.