Beispiel #1
0
def evaluate_time_series_expression(expression, rrd_data) -> List[TimeSeries]:
    if rrd_data:
        sample_data = next(iter(rrd_data.values()))
        num_points = len(sample_data)
        twindow = sample_data.twindow
    else:
        # no data, default clean graph, use for pure scalars on custom graphs
        num_points = 1
        twindow = (0, 60, 60)

    if expression[0] == "operator":
        operator_id, operands = expression[1:]
        operands_evaluated_l = [evaluate_time_series_expression(a, rrd_data) for a in operands]
        operands_evaluated = [item for lists in operands_evaluated_l for item in lists]
        return [time_series_math(operator_id, operands_evaluated)]

    if expression[0] == "transformation":
        (transform, conf), operands = expression[1:]
        operands_evaluated = evaluate_time_series_expression(operands[0], rrd_data)
        return evaluate_timeseries_transformation(transform, conf, operands_evaluated)

    if expression[0] == "rrd":
        key = tuple(expression[1:])
        if key in rrd_data:
            return [rrd_data[key]]
        return [TimeSeries([None] * num_points, twindow)]

    if expression[0] == "constant":
        return [TimeSeries([expression[1]] * num_points, twindow)]

    if expression[0] == "combined":
        metrics = resolve_combined_single_metric_spec(expression[1])
        curves = []
        for m in metrics:
            for curve in evaluate_time_series_expression(m['expression'], rrd_data):
                curve.metadata = {k: m[k] for k in m if k in ['line_type', 'title']}
                curves.append(curve)

        return curves

    raise NotImplementedError()
Beispiel #2
0
def evaluate_time_series_expression(expression, rrd_data):
    if rrd_data:
        sample_data = next(iter(rrd_data.values()))
        num_points = len(sample_data)
        twindow = sample_data.twindow
    else:
        # no data, default clean graph, use for pure scalars on custom graphs
        num_points = 1
        twindow = (0, 60, 60)

    if expression[0] == "operator":
        operator_id, operands = expression[1:]
        operands_evaluated = [evaluate_time_series_expression(a, rrd_data) for a in operands]
        return time_series_math(operator_id, operands_evaluated)

    if expression[0] == "transformation":
        (transform, conf), operands = expression[1:]
        operands_evaluated = evaluate_time_series_expression(operands[0], rrd_data)
        return evaluate_timeseries_transformation(transform, conf, operands_evaluated)

    if expression[0] == "rrd":
        key = tuple(expression[1:])
        if key in rrd_data:
            return rrd_data[key]
        return TimeSeries([None] * num_points, twindow)

    if expression[0] == "constant":
        return TimeSeries([expression[1]] * num_points, twindow)

    if expression[0] == "combined":
        metrics = resolve_combined_single_metric_spec(expression[1])

        return [(m["line_type"], m["color"], m['title'],
                 evaluate_time_series_expression(m['expression'], rrd_data)) for m in metrics]

    raise NotImplementedError()
Beispiel #3
0
 def resolve_combined_single_metric_spec(expression):
     return evaluate_timeseries_transformation(None, None, None)
Beispiel #4
0
        # no data, default clean graph, use for pure scalars on custom graphs
        num_points = 1
        twindow = (0, 60, 60)

    if expression[0] == "operator":
        operator_id, operands = expression[1:]
        operands_evaluated = list(
            chain.from_iterable(evaluate_time_series_expression(a, rrd_data) for a in operands))
        if result := time_series_math(operator_id, operands_evaluated):
            return [result]
        return []

    if expression[0] == "transformation":
        (transform, conf), operands = expression[1:]
        operands_evaluated = evaluate_time_series_expression(operands[0], rrd_data)
        return evaluate_timeseries_transformation(transform, conf, operands_evaluated)

    if expression[0] == "rrd":
        key = tuple(expression[1:])
        if key in rrd_data:
            return [rrd_data[key]]
        return [TimeSeries([None] * num_points, twindow)]

    if expression[0] == "constant":
        return [TimeSeries([expression[1]] * num_points, twindow)]

    if expression[0] == "combined":
        metrics = resolve_combined_single_metric_spec(expression[1])
        curves = []
        for m in metrics:
            for curve in evaluate_time_series_expression(m['expression'], rrd_data):