Mini Shell

Direktori : /opt/imh-python/lib/python3.9/site-packages/fpmstatus/
Upload File :
Current File : //opt/imh-python/lib/python3.9/site-packages/fpmstatus/report.py

# vim: set ts=4 sw=4 expandtab syntax=python:
"""

fpmstatus.report
ANSI & HTML report generator

@author J. Hipps <jacobh@inmotionhosting.com>

"""

import logging

import arrow
from prettytable import PrettyTable

from fpmstatus.util import *

logger = logging.getLogger('fpmstatus')
last_master = None

def repgen_pool(pdata, compact):
    """
    Generate a verbose report
    """
    if pdata.get('_config'):
        print(strcolor('white', "*** %s [%s] ***" % (pdata['_config']['_vhost'], pdata['pool'])))
    else:
        print(strcolor('white', "*** %s ***" % (pdata['pool'])))

    pt = PrettyTable()
    pt.field_names = ('Pool Config', '')
    if pdata.get('_config'):
        if pdata['_config'].get('_masterid'):
            pt.add_row(('Master ID', pdata['_config'].get('_masterid')))
            pt.add_row(('Master Log', pdata['_config'].get('_masterlog')))
        pt.add_row(('User/Group', pdata['_config'].get('user') + ':' + pdata['_config'].get('group')))
        pt.add_row(('Socket', pdata['_config']['listen']))
        pt.add_row(('Config Path', pdata['_config']['_confpath']))
        pt.add_row(('Document Root', pdata['_config'].get('php_admin_value[doc_root]', '<not set>').replace('"', '')))
        pt.add_row(('Error Log', pdata['_config'].get('php_admin_value[error_log]', '<not set>').replace('"', '')))
        pt.add_row((strcolor('gray', 'Process Manager Params'), strcolor('gray', '----')))
        pt.add_row(('PM Type', pdata['_config'].get('pm')))
        pt.add_row(('Max Children', pdata['_config'].get('pm.max_children')))
        pt.add_row(('Max Requests', pdata['_config'].get('pm.max_requests')))
        pt.add_row(('Process Idle Timeout', pdata['_config'].get('pm.process_idle_timeout')))
        pt.add_row(('Max Children', pdata['_config'].get('pm.max_children')))
        pt.add_row(('Max Spare Servers', pdata['_config'].get('pm.max_spare_servers')))
        pt.add_row(('Min Spare Servers', pdata['_config'].get('pm.min_spare_servers')))
        pt.add_row(('Start Servers', pdata['_config'].get('pm.start_servers')))
        pt.add_row(('RLimit Files', pdata['_config'].get('rlimit_files', '<OS default>')))
    pt.align['Pool Config'] = 'r'
    pt.align[''] = 'l'
    print(pt.get_string())

    pt = PrettyTable()
    pt.field_names = ('Pool Stats', '')
    pt.add_row(('Start Time', arrow.get(pdata['start_time']).format('YYYY-MM-DD HH:mm:ss')))
    pt.add_row(('Runtime Duration', format_uptime(pdata['start_since'])))
    pt.add_row(('Conn Accepted', pdata['accepted_conn']))
    pt.add_row(('Procs Total', pdata['total_processes']))
    pt.add_row(('Procs Idle', pdata['idle_processes']))
    pt.add_row(('Procs Active', pdata['active_processes']))
    pt.add_row(('Max Active Procs', pdata['max_active_processes']))
    pt.add_row(('Max Children Reached', pdata['max_children_reached']))
    pt.add_row(('Listen Queue', pdata['listen_queue']))
    pt.add_row(('Listen Queue (Max)', pdata['max_listen_queue']))
    pt.add_row(('Listen Queue Len', pdata['listen_queue_len']))
    pt.add_row(('Slow Requests', pdata['slow_requests']))
    pt.align['Pool Stats'] = 'r'
    pt.align[''] = 'l'
    print(pt.get_string())

    if compact:
        return
    for tpnum, tproc in enumerate(pdata['processes']):
        pt = PrettyTable()
        pt.field_names = (strcolor('white', 'Worker Process'), strcolor('gray', '[#%d] pid %d' % (tpnum, tproc['pid'])))
        pt.add_row(('State', strcolor('yellow', tproc['state'])))
        pt.add_row(('Script', strcolor('cyan', tproc['script'])))
        pt.add_row((strcolor('gray', 'Worker Stats'), strcolor('gray', '----')))
        pt.add_row(('Start Time', arrow.get(tproc['start_time']).format('YYYY-MM-DD HH:mm:ss')))
        pt.add_row(('Runtime Duration', format_uptime(tproc['start_since'])))
        pt.add_row(('Requests', tproc['requests']))
        pt.add_row((strcolor('gray', 'Last Request Stats'), strcolor('gray', '----')))
        pt.add_row(('Request URI', strcolor('white', tproc['request_uri'])))
        pt.add_row(('Request Method', tproc['request_method']))
        pt.add_row(('CPU Time', tproc['last_request_cpu']))
        pt.add_row(('Memory Usage', tproc['last_request_memory']))
        pt.add_row(('Request Duration', '%f s' % (tproc['request_duration'])))
        pt.align[pt.field_names[0]] = 'r'
        pt.align[pt.field_names[1]] = 'l'
        print(pt.get_string())

    print('=' * 80 + '\n')


def repgen_pool_terse(pdata):
    """
    Generate a terse report
    """
    global last_master

    if pdata.get('_config'):
        if pdata['_config'].get('_masterid'):
            if last_master != pdata['_config']['_masterid']:
                print("\n[%s]" % (strcolor('green', pdata['_config']['_masterid'])))
                last_master = pdata['_config']['_masterid']

        print("+--[ %s | %s ]" % (strcolor('white', pdata.get('pool')), strcolor('yellow', pdata['_config'].get('_vhost'))))
        print("|  | %s:%s - %s" % (pdata['_config'].get('user'), pdata['_config'].get('group'), pdata['_config'].get('php_admin_value[doc_root]', '').replace('"', '')))
        print("|  | %s (%s/%s/%s) <%s>" % (pdata['_config'].get('pm'), pdata['_config'].get('pm.max_children'), pdata['_config'].get('pm.max_requests'), pdata['_config'].get('pm.process_idle_timeout'), pdata['_config'].get('listen')))
    else:
        print("+--[ %s ]" % (pdata['pool']))

    for tproc in pdata['processes']:
        print("|  +--< pid %s / %s / %s >" % (strcolor('white', tproc['pid']), strcolor('yellow', tproc['state']), strcolor('cyan', tproc['script'])))
        print("|  |    %f s / %s cps / %s" % (tproc['request_duration'], tproc['last_request_cpu'], format_size(tproc['last_request_memory'])))

    print("|")

Zerion Mini Shell 1.0