Beispiel #1
0
def process_tplayloading_qos(request, table, choketype, title, subtitle,
                             y_title, view_types, pn_types):
    begin_time = time.time()
    items = []

    try:
        (service_type, device_type, device_types, version, versions,
         begin_date, end_date, min_rec) = get_loading_param_values(request)
        if device_type == "":
            raise NoDataError(
                "No data between {0} and {1} in tplayloading".format(
                    begin_date, end_date))

        filter_params = FilterParams(table, service_type, device_type,
                                     begin_date, end_date)
        if begin_date == end_date:
            data_by_hour = prepare_hour_data(filter_params, version, choketype,
                                             view_types, pn_types)
            if data_by_hour is None:
                raise NoDataError(
                    "No hour data between {0} and {1} in tplayloading".format(
                        begin_date, end_date))

            item_idx = 0
            for (view_type_idx, view_desc) in view_types:
                if view_type_idx not in data_by_hour:
                    continue
                item = make_loading_item(data_by_hour[view_type_idx], pn_types,
                                         item_idx, HOUR_X_AXIS, title,
                                         "%s %s" % (subtitle, view_desc),
                                         y_title)
                items.append(item)
                item_idx += 1

        else:
            days_region = get_days_region(begin_date, end_date)
            data_by_day = prepare_daily_data(filter_params, version, choketype,
                                             days_region, view_types, pn_types)
            if data_by_day is None:
                raise NoDataError(
                    "No daily data between {0} and {1} in tplayloading".format(
                        begin_date, end_date))

            format_days_region = [
                "%s%s" % (i[5:7], i[8:10]) for i in days_region
            ]
            item_idx = 0
            for (view_type_idx, view_desc) in view_types:
                if view_type_idx not in data_by_day:
                    continue
                item = make_loading_item(data_by_day[view_type_idx], pn_types,
                                         item_idx, format_days_region, title,
                                         "%s %s" % (subtitle, view_desc),
                                         y_title)
                items.append(item)
                item_idx += 1

    except Exception, e:
        logger.info("query {0} {1} error: {2}".format(table.__name__,
                                                      choketype, e))
Beispiel #2
0
def process_multi_plot(request, table, title, subtitle, y_title, view_types, pn_types, base_radix=1):
    begin_time = current_time()
    items = []

    try:
        (service_type, device_type, device_types,
            version, versions, begin_date, end_date) = get_filter_param_values(request)
        if device_type == "":
            raise NoDataError("No data between {0} and {1} in tplay_title".format(begin_date, end_date))

        if version == "All":
            device_type_full = device_type
        else:
            device_type_full = '{0}_{1}'.format(device_type, version)

        filter_params = FilterParams(table, service_type, device_type_full, begin_date, end_date)

        if begin_date == end_date:
            data_by_hour = prepare_pnvalue_hour_data(filter_params, view_types, pn_types, base_radix)

            if data_by_hour is None:
                raise NoDataError("No hour data between {0} and {1}".format(begin_date, end_date))

            item_idx = 0
            for (view_type_idx, view_des) in view_types:
                if view_type_idx not in data_by_hour:
                    continue

                item = make_plot_item(data_by_hour[view_type_idx], pn_types, item_idx, HOUR_X_AXIS, title,
                                      "%s %s" % (subtitle, view_des), y_title)
                if item:
                    items.append(item)
                    item_idx += 1
        else:
            days_region = get_days_region(begin_date, end_date)
            data_by_day = prepare_pnvalue_daily_data(filter_params, days_region, view_types,
                                                     pn_types, base_radix)
            if data_by_day is None:
                raise NoDataError("No daily data between %s - %s" % (begin_date, end_date))

            format_days_region = ["%s%s" % (i[5:7], i[8:10]) for i in days_region]
            item_idx = 0
            for (view_type_idx, view_des) in view_types:
                if view_type_idx not in data_by_day:
                    continue
                item = make_plot_item(data_by_day[view_type_idx], pn_types, item_idx, format_days_region, title,
                                      "%s %s" % (subtitle, view_des), y_title)
                if item:
                    items.append(item)
                    item_idx += 1

    except Exception, e:
        logger.info("query %s multiQos error: %s" % (table.__name__, e))
Beispiel #3
0
def process_single_qos(request, table, qos_name, title, subtitle, y_title, view_types, hour_flag, base_radix=1):
    begin_time = time.time()
    items = []

    try:
        (service_type, device_type, device_types,
            version, versions, begin_date, end_date) = get_filter_param_values(request)

        if device_type == "":
            raise NoDataError("No data between {0} and {1} in tplay_title".format(begin_date, end_date))

        if version == "All":
            device_type_full = device_type
        else:
            device_type_full = '{0}_{1}'.format(device_type, version)

        filter_params = FilterParams(table, service_type, device_type_full, begin_date, end_date)

        # ViewType (0, '总体') indicates total, if so, it should be the first item of view_types
        if 0 in view_types[0] and len(view_types) > 1:
            need_total = True
        else:
            need_total = False

        if begin_date == end_date and hour_flag:
            data_by_hour = prepare_hour_data_of_single_qos(
                filter_params, view_types, qos_name, base_radix, need_total)

            if data_by_hour is None:
                raise NoDataError("No hour data between {0} and {1}".format(begin_date, end_date))

            item = make_plot_item(data_by_hour, view_types, 0, HOUR_X_AXIS, title, subtitle, y_title,
                                  remove_zero_serie=True)
            items.append(item)
        else:
            days_region = get_days_region(begin_date, end_date)
            data_by_day = prepare_daily_data_of_single_qos(
                filter_params, days_region, view_types, qos_name, hour_flag, base_radix, need_total)
            if data_by_day is None:
                raise NoDataError("No daily data between {0} and {1}".format(begin_date, end_date))

            format_days_region = ["%s%s" % (i[5:7], i[8:10]) for i in days_region]
            item = make_plot_item(data_by_day, view_types, 0, format_days_region, title, subtitle, y_title,
                                  remove_zero_serie=True)
            items.append(item)

    except Exception, e:
        logger.info("query {0} {1} error: {2}".format(table.__name__, qos_name, e))
Beispiel #4
0
def get_ratio_history(ip, code, begin_date, end_date):
    keys = [(0, 0, u"%d占比" % code), (1, 1, u"记录数")]

    if begin_date == end_date:
        xalis = ["%d:00" % i for i in range(24)]
    else:
        days_region = get_days_region(begin_date, end_date)
        xalis_day = [i for i in days_region]
        xalis = []
        for d in xalis_day:
            xalis_hour = ["%s:00" % i for i in range(24)]
            xalis_hour[0] = d
            xalis += xalis_hour

    datas = prepare_hourly_ratio_history(ip, code, begin_date, end_date, xalis)
    if datas is None:
        raise NoDataError("No data between %s - %s" % (begin_date, end_date))

    interval = get_multidays_interval(len(xalis) / 24)
    item = make_plot_item2(datas, keys, 0, xalis, (u"%d占比及记录数" % code), "",
                           u"百分比(%)", interval, u"记录数")

    return item
Beispiel #5
0
def get_delay_history(ip, code, begin_date, end_date):
    keys = [(0, 0, "P25"), (1, 0, "P50"), (2, 0, "P75"), (3, 0, "P90"),
            (4, 0, "P95")]

    if begin_date == end_date:
        xalis = ["%d:00" % i for i in range(24)]
    else:
        days_region = get_days_region(begin_date, end_date)
        xalis_day = [i for i in days_region]
        xalis = []
        for d in xalis_day:
            xalis_hour = ["%s:00" % i for i in range(24)]
            xalis_hour[0] = d
            xalis += xalis_hour

    datas = prepare_hourly_delay_history(ip, code, begin_date, end_date, xalis)
    if datas is None:
        raise NoDataError("No data between %s - %s" % (begin_date, end_date))

    interval = get_multidays_interval(len(xalis) / 24)
    item = make_plot_item2(datas, keys, 1, xalis, u"服务器响应时延", "", u"时延(ms)",
                           interval)

    return item