コード例 #1
0
def test_horizontal_rules_from_thresholds(perf_string, result):
    assert (utils.horizontal_rules_from_thresholds(
        [
            "one:warn",
            ("power:crit", "Critical power"),
            ("output:warn,-1,*", "Warning output"),
        ],
        metrics.translate_perf_data(perf_string),
    ) == result)
コード例 #2
0
def create_graph_recipe_from_template(graph_template: GraphTemplate,
                                      translated_metrics: TranslatedMetrics,
                                      row: Row) -> GraphRecipe:
    def _metric(metric_definition: MetricDefinition) -> GraphMetric:
        metric = GraphMetric({
            "title":
            metric_line_title(metric_definition, translated_metrics),
            "line_type":
            metric_definition[1],
            "expression":
            metric_expression_to_graph_recipe_expression(
                metric_definition[0],
                translated_metrics,
                row,
                graph_template.get("consolidation_function", "max"),
            ),
        })

        unit_color = metric_unit_color(metric_definition[0],
                                       translated_metrics)
        if unit_color:
            metric.update({
                "color": unit_color["color"],
                "unit": unit_color["unit"],
            })
        return metric

    metrics = list(map(_metric, graph_template["metrics"]))
    units = {m["unit"] for m in metrics}
    if len(units) > 1:
        raise MKGeneralException(
            _("Cannot create graph with metrics of "
              "different units '%s'") % ", ".join(units))

    title = replace_expressions(str(graph_template.get("title", "")),
                                translated_metrics)
    if not title:
        title = next((m["title"] for m in metrics if m["title"]), "")

    return {
        "title":
        title,
        "metrics":
        metrics,
        "unit":
        units.pop(),
        "explicit_vertical_range":
        get_graph_range(graph_template, translated_metrics),
        "horizontal_rules":
        horizontal_rules_from_thresholds(
            graph_template.get("scalars", []),
            translated_metrics),  # e.g. lines for WARN and CRIT
        "omit_zero_metrics":
        graph_template.get("omit_zero_metrics", False),
        "consolidation_function":
        graph_template.get("consolidation_function", "max"),
    }
コード例 #3
0
def create_graph_recipe_from_template(graph_template, translated_metrics, row):
    def _metrics(metric_definition):
        return {
            **metric_unit_color(metric_definition[0], translated_metrics), "title":
            metric_line_title(metric_definition, translated_metrics),
            "line_type":
            metric_definition[1],
            "expression":
            metric_expression_to_graph_recipe_expression(
                metric_definition[0], translated_metrics, row,
                graph_template.get("consolidation_function", "max"))
        }

    metrics = list(map(_metrics, graph_template['metrics']))
    units = {m['unit'] for m in metrics}
    if len(units) > 1:
        raise MKGeneralException(
            _("Cannot create graph with metrics of "
              "different units '%s'") % ", ".join(units))

    title = replace_expressions(graph_template.get("title", ""),
                                translated_metrics)
    if not title:
        title = next((m['title'] for m in metrics if m['title']), "")

    return {
        "title":
        title,
        "metrics":
        metrics,
        "unit":
        units.pop(),
        "explicit_vertical_range":
        get_graph_range(graph_template, translated_metrics),
        "horizontal_rules":
        horizontal_rules_from_thresholds(
            graph_template.get("scalars", []),
            translated_metrics),  # e.g. lines for WARN and CRIT
        "omit_zero_metrics":
        graph_template.get("omit_zero_metrics", False),
        "consolidation_function":
        graph_template.get("consolidation_function", "max"),
    }