Multiple metrics in one graph

Using a local check script, can I create ‘grouped’ or ‘stacked’ items?

As of now, every alert rule i create is set as a single item.

This is an example of what i mean with this:
Screenshot 2024-10-09 at 16.13.12

Here we see multiple items in one single view: Swap used, Ram used, swap installed and ram installed.

This is a graph with multiple metrics in Checkmk’s terms.

You can create your own graph definitions in the code.

A bit of documentation is available here: Writing agent-based check plug-ins

I don’t understand. I’m creating a standalone local check script on a vm.
On that vm, should i install some cmk python module then?

We currently have simple scripts, e.g. something with an if/else statement, and eventually it prints:

0 my_service myvalue=1 some message

I’d like to keep this simplicity, in this one file.

If your locale/mrpe check returns multiple metrics, checkmk will by default create a separate graph for each metric. As Robert mentioned, you will need to create your own graph definition on the checkmk server if you want to display these metrics in a combined graph.

Since Checkmk already comes with a large number of chart definitions, it is important that your loalc/mrpe check uses distinct metric names so that your graph definition uses the correct metrics.

1 Like

Examle: ~/local/share/check_mk/web/plugins/metrics/demo_metrics.py

from cmk.gui.i18n import _

from cmk.gui.plugins.metrics import (
    metric_info,
    graph_info,
)

metric_info["demo_warn"] = {
    "title": _("Demo warn"),
    "unit": "count",
    "color": "15/a",
}

metric_info["demo_crit"] = {
    "title": _("Demo crit"),
    "unit": "count",
    "color": "24/a",
}

graph_info["demo_combined"] = {
    "title": _("Number of Warnings/Criticals "),
    "metrics": [
        ("demo_warn", "line"),
        ("demo_crit", "line"),
    ],
}
1 Like

I have also been struggling to combine output into a single graph.
Having looked at your example, and what i had found on my own i am (most likely) still missing something important.

so real example of the output (in this case a datasource program):

<<<local>>>
P active_tariff tariff=1;;;;; Current Tariff:1
P active_power_w watt=1812.0;2100;2200;2300;0;2500 Current Watts:1812.0
P active_power_l1_w watt=346.0;2100;2200;2300;0;2500 Current Watts:346.0
P active_power_l2_w watt=1290.0;2100;2200;2300;0;2500 Current Watts:1290.0
P active_power_l3_w watt=186.0;2100;2200;2300;0;2500 Current Watts:186.0
P active_voltage_l1_v volt=229.5;252;253;260;0;300 Current Volts:229.5
P active_voltage_l2_v volt=222.5;252;253;260;0;300 Current Volts:222.5
P active_voltage_l3_v volt=230.0;252;253;260;0;300 Current Volts:230.0
P active_current_a amps=8.114;8;10;15;0;20 Current Amps:8.114
P active_current_l1_a amps=1.508;8;10;15;0;20 Current Amps:1.508
P active_current_l2_a amps=5.798;8;10;15;0;20 Current Amps:5.798
P active_current_l3_a amps=0.809;8;10;15;0;20 Current Amps:0.809

With what i found, and read on this this topic i created the following metric file, and placed it accordingly in ~/local/share/check_mk/web/plugins/metrics/my metrics-file.py and made it executable.

#!/usr/bin/env python3
#
# This file is for combining metrics of a P1 Meter from https://www.homewizard.com/ in Checkmk (https://checkmk.com). 
#

from cmk.gui.i18n import _
from cmk.gui.plugins.metrics.utils import graph_info, metric_info

# .
#   .--Metrics-------------------------------------------------------------.
#   |                   __  __      _        _                             |
#   |                  |  \/  | ___| |_ _ __(_) ___ ___                    |
#   |                  | |\/| |/ _ \ __| '__| |/ __/ __|                   |
#   |                  | |  | |  __/ |_| |  | | (__\__ \                   |
#   |                  |_|  |_|\___|\__|_|  |_|\___|___/                   |
#   |                                                                      |
#   +----------------------------------------------------------------------+
#   |  Definitions of metrics                                              |
#   '----------------------------------------------------------------------'

# Title are always lower case - except the first character!
# Colors: See indexed_color() in cmk/gui/plugins/metrics/utils.py

metric_info["active_power_w"] = {
    "title": _("Total active power"),
    "unit": "w",
    "color": "31/a",
}

metric_info["active_power_l1_w"] = {
    "title": _("Active power phase 1"),
    "unit": "w",
    "color": "#40a0b0",
}

metric_info["active_power_l2_w"] = {
    "title": _("Active power phase 2"),
    "unit": "w",
    "color": "#ff6000",
}

metric_info["active_power_l3_w"] = {
    "title": _("Active power phase 3"),
    "unit": "w",
    "color": "43/a",
}

# .
#   .--Graphs--------------------------------------------------------------.
#   |                    ____                 _                            |
#   |                   / ___|_ __ __ _ _ __ | |__  ___                    |
#   |                  | |  _| '__/ _` | '_ \| '_ \/ __|                   |
#   |                  | |_| | | | (_| | |_) | | | \__ \                   |
#   |                   \____|_|  \__,_| .__/|_| |_|___/                   |
#   |                                  |_|                                 |
#   +----------------------------------------------------------------------+
#   |  Definitions of time series graphs                                   |
#   '----------------------------------------------------------------------'

graph_info["p1_power"] = {
    "title": _("P1 power"),
    "metrics": [
        ("active_power_w", "stack"),
        ("active_power_l1_w", "stack"),
        ("active_power_l2_w", "stack"),
        ("active_power_l3_w", "stack"),
    ],
}

It is my goal to group Watts, Volts and Amps into their own (combined) graph.
Unfortunately i have not been able to achieve it till now.

Any help as to what i am missing due to lack of knowledge is highly appreciated

  • Glowsome

With this local check script output 12 separate checks are created.
The metrics of these checks cannot be combined with a graph definition as they are separate checks.

You can use a custom graph or a combined graph (available in the enterprise editions).

Thank you for the answer.
I’ll have to abandon this then as i have the RAW version.

  • Glowsome

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.