[solved] Changes to metric_info()/graph_info() don't get visible

Hi,

I am trying to learn how to write my own check plug-ins. I’m starting with “CIFS shares”, which should basically be “CIFS mounts” but the combination of server and share name shall be unique. Yes, some moron made a dozen mounts to the same server/share. That will be cleaned up later.

I have /usr/lib/check_mk_agent/plugins/ALH_cifsshares which gives me:

<<<alh_cifsshares>>>
hdmssrv.hn.de/archive ok 456340275200 123522686976
hdmssrv.hn.de/sue ok 30064771072 20539867136

On the server I have ~/local/lib/check_mk/base/plugins/agent_based/alh_cifsshares.py:

#!/usr/bin/env python3

from .agent_based_api.v1 import *
import pprint

def discover_cifsshares(section):
    for share, state, total, free in section:
        yield Service(item=share)

def check_cifsshares(item, section):
    for share, state, total, free in section:
        if share == item:
            total = int(total)
            free = int(free)

            used = total - free
            if total != 0:
                pctused = 100.0 * used / total
            else:
                pctused = 0
            if state == "ok":
                s = State.OK
            else:
                s = State.CRIT

            yield Metric("cifstotal", total)
            yield Metric("cifsused",
                    used,
                    levels=(0.85 * total, 0.95 * total)
            )
            yield Metric("cifsfree", free)
            yield Metric("cifspctused", pctused)

            yield Result(
                state = s,
                summary = "%s used (%s of %s), state=%s" % (
                    render.percent(pctused),
                    render.disksize(used),
                    render.disksize(total),
                    state,
                )
            )
            return

register.check_plugin(
    name="alh_cifsshares",
    service_name="CIFS share %s",
    discovery_function=discover_cifsshares,
    check_function=check_cifsshares,
)

Then I have ~/local/share/check_mk/web/plugins/metrics/alh_cifsshares.py:

#!/usr/bin/env python3

from cmk.gui.i18n import _
from cmk.gui.plugins.metrics.utils import *

metric_info["cifstotal"] = {
    "title": _("Filesystem size"),
    "unit": "bytes",
    "color": "13/a",
    # red
}

metric_info["cifsfree"] = {
    "title": _("Free spice"),
    "unit": "bytes",
    "color": "23/a",
    # yellow
}

metric_info["cifsused"] = {
    "title": _("Used filesystem space"),
    "unit": "bytes",
    "color": "33/a",
    # green
}

metric_info["cifspctused"] = {
    "title": _("Used filesystem space %"),
    "unit": "%",
    "color": "43/a",
    # blue
}

graph_info["cifscombined"] = {
    "title": _("Filesystem size and used spice"),
    "metrics": [
        ("cifsused", "area"),
        ("cifsfree", "stack"),
        ("cifstotal", "line"),
    ],
    "conflicting_metrics": ["cifspctused"],
}

Last not least I have ~/local/share/check_mk/web/plugins/perfometer/alh_cifsshares.py:

#!/usr/bin/env python3

from cmk.gui.i18n import _
from cmk.gui.plugins.metrics.utils import *

perfometer_info.append({
    "type": "linear",
    "segments": ["cifspctused"],
    "total": 100.0,
})

This gives me:


Why is the perfometer purple? I would expect it to be blue ("color": "43/a").

Also it gives me:

Why is it not “Free spice” but “Free space 2” (something I tested earlier)?

Why is it not “Filesystem size and used spice” and not "“Filesystem size and used space” (something I tested earlier)?

Why does the first graph uses different shades of green instead of red, yellow and green?

Why ist there a second graph “Cifspctused” although I configured "conflicting_metrics": ["cifspctused"] at the first graph?

Kind regards,
Robert

This can happen if you change something on your metric files and don’t restart the Apache after this change.
For all tests with your own metric names and graph definitions you should restart the site Apache.

Hi Andreas,

Thank you very much! This indeed fixed the titles and the colors. Would be nice if that were mentioned somewhere in the docs.

Anyway: now I get 4 graphs for my 4 metrics, they no longer get combined by graph_info(). Do you have a tip how to debug this?

Kind regards,
Robert

The culprit is "conflicting_metrics": ["cifspctused"],. As soon as I comment that out I get the combined graph and a second graph with “Used filesystem space %”. How do I get rid of the second graph?

Kind regards,
Robert

You need to add the following to your metric file.

check_metrics["check_mk-alh_cifsshares"] = {
    "cifspctused": {"auto_graph": False}
}

Andreas, within two hours you made my day twice. :slight_smile:

Some documentation for all that surely would be useful.

Kind regards,
Robert

@bornheim

Can you please mark @andreas-doehler 's answer as the solution if it solved your problem?

I shouldn’t until some decent documentation is available. :slight_smile:
But I did …

R.

1 Like

@bornheim Touché :slight_smile: