晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 sh-3ll

HOME


sh-3ll 1.0
DIR:/opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/chart/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/lvestats/lib/chart/dbgovchartmain.py
# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

from lvestats.lib import lveinfolib_gov
from lvestats.lib.chart import ChartMain
from lvestats.lib.commons import dateutil, sizeutil

VERSION = '0.10'


def _io_units(v):
    """
    Get string representation of value;
    :param int v: value in megabytes
    :return str: humanized value

    >>> _io_units(1)
    '1MB'
    >>> _io_units(1024)
    '1GB'
    """
    return sizeutil.convert_bytes_for_graph(v * 1024 * 1024)


class DbGovChart(ChartMain):
    def __init__(self, config=None):
        super().__init__('dbgovchart',
                         'Creates a chart representing usage pattern for LVE/user',
                         config)

    @staticmethod
    def get_version():
        return VERSION

    def get_chart_data(self, engine, from_ts, to_ts, server, user_id=None, show_all=False):
        utc_from = dateutil.local_to_gm(from_ts)
        utc_to = dateutil.local_to_gm(to_ts)

        dt = utc_to - utc_from
        period_sec = dt.total_seconds()
        show_columns = ('ts', 'cpu', 'lcpu', 'read', 'lread', 'write', 'lwrite')
        data = lveinfolib_gov.HistoryShowDBGov(
            engine,
            utc_from,
            utc_to,
            uid=user_id,
            server_id=server,
            show_columns=show_columns,
            cfg=self.cfg
        ).history_dbgov_show()
        data_collected = DbGovChart.convert_dbdata_to_dict(data, show_columns)
        times = data_collected['ts']
        del data_collected['ts']
        return data_collected, times, period_sec

    def customize_parser(self, parser):
        parser.add_argument('--user',
                            help='mysql username',
                            dest='user_name',
                            required=True)
        return parser

    def add_graphs(self, renderer, data_collected, times, lve_version, show_all, is_user=False):
        if any(data_collected['lcpu']) or show_all:
            if is_user and self.is_normalized_user_cpu:
                # Magnify aCPU, lCPU to 100%
                # New user's data and limits
                a_cpu_new = []
                l_cpu_new = []
                for idx in range(0, len(data_collected['lcpu'])):
                    l_cpu = data_collected['lcpu'][idx]
                    a_cpu = data_collected['cpu'][idx]
                    # New limit
                    l_cpu_new.append(100.0)
                    # New average
                    a_cpu_new.append(a_cpu * 100.0 / l_cpu)
                # Store new data
                data_collected['lcpu'] = l_cpu_new
                data_collected['cpu'] = a_cpu_new
            renderer.add_graph(data_collected, 'CPU Usage',
                               legend={
                                   'cpu': ('CPU', 'green', int),
                                   'lcpu': ('limit', 'red'),
                               }, x_values=times, min_y=0, max_y=100, unit='%', y_legend_converter=int)
        if any(data_collected['lread']) or show_all:
            renderer.add_graph(data_collected, 'Read Usage',
                               legend={
                                   'read': ('READ', 'green',),
                                   'lread': ('limit', 'red'),
                               }, x_values=times, min_y=0, y_legend_converter=_io_units, unit='/s')
        if any(data_collected['lwrite']) or show_all:
            renderer.add_graph(data_collected, 'Write Usage',
                               legend={
                                   'write': ('WRITE', 'green',),
                                   'lwrite': ('limit', 'red'),
                               }, x_values=times, min_y=0, y_legend_converter=_io_units, unit='/s')

        if not show_all and not any(data_collected.values()):
            # if no data available draw text box
            renderer.add_text_box("No data")

        renderer.add_common_x_legend(times, 6)

# Uncomment this if you want to test it.
# if __name__ == "__main__":
#     DbGovChart(config_for_debug={
#         'db_type': 'sqlite',
#         'sqlite_db_path': '/home/shaman/workspace/cloudlinux/dbgovdb/lvestats2.db',
#         'server_id': 'localhost',
#     }).main('--from', '2015-03-12 00:00', '--to', '2015-04-01 00:00', '--user', 'mysqldd', '--output', '/tmp/1.svg')