How can I specify metric names containing blanks in local checks?

Hi, I’m currently writing a local check where I’d like the metrics to have whitespace (blanks), i.e. in the graphs I’d like to see “My Metric” and not “my_metric”. How can this be achieved? Setting the metric name in quotes in the output (‘…"My Metric=12…’) doesn’t seem to work. Escaping the blank (‘…"My\ Metric=12…’) doesn’t work either. Is this possible for local checks at all?

The metric value name cannot have spaces. But you can define a metric and graph definition for your check, than it draws the metrics from your check with understandable names.

Some example and a discussion for this you can find here.

2 Likes

Thank you very much @andreas-doehler , this is very helpful. I’ll give it a try :slight_smile:

Local Check - specify correct Unit for Graph Metric already helped, but I realized, that with this method I have to also specify color and unit, otherwise I get ugly Python tracebacks instead of a graph :-), but I’d like to only set the title and leave the rest up to Checkmk (which does a pretty good job). This one worked fine:

metric_info["mymetric"] = {
    "title": _('my metric title with blanks'),
    "color": "#0000cc",
    "unit":  "count"
}

but this statement - when omitting the above assigment - didn’t have any effect at all:

metric_info["mymetric"]["title"] = "my metric title with blanks"

also not:

metric_info["mymetric"]["title"] = _("my metric title with blanks")

The single-line assignments only had an effect, if prior to them, the block with the complete dictionary was executed. Isn’t it possible to set single properties of a custom check metric?

I think the short answer is no. For every metric, in your case “mymetric”, you need to specify a title, color and unit. If the name “mymetric” exists already then you don’t need to specify anything.

Pity, but thanks a lot for the quick answer @andreas-doehler