External metric in own graph

Hi @Sara ,

the next topic for the developer hour:

I have a check plugin with its own metrics and an “external” metric name:

The metric name “requests_per_second” is now defined in ~/lib/python3/cmk/plugins/collection/graphing/apache.py.

After converting my metrics definitions the graph tells me that the units are not compatible:

Cannot calculate graph recipes
Cannot create graph with metrics of different units 'DecimalNotation_/s_AutoPrecision_2, 1/s'

When I try to define requests_per_sec myself the web.log contains cmk_addons.plugins.ox_imageconverter.graphing.ox_imageconverter:metric_requests_noncached_images: plug-in 'requests_per_second' already defined at cmk.plugins.collection.graphing.apache:metric_requests_per_second.

Why do you make it so hard to migrate to Check API v2?

2 Likes

It gets even better: There are two conflicting definitions of the metric “requests_per_sec” in the upstream code.

One is in $OMD_ROOT/lib/python3/cmk/gui/plugins/metrics/network.py in old style:

metric_info["requests_per_sec"] = {
    "title": _("Requests per second"),
    "unit": "1/s",
    "color": "36/a",
}

The other is in $OMD_ROOT/lib/python3/cmk/plugins/collection/graphing/apache.py in new style:

metric_requests_per_second = metrics.Metric(
    name="requests_per_second",
    title=Title("Requests per second"),
    unit=metrics.Unit(metrics.DecimalNotation("req/s")),
    color=metrics.Color.GRAY,
)

And they use different units. And it looks like the older style takes precedence. I am not able to define a unit in my new style metrics that matches the converted unit from the old style. :frowning_face:

That’s really a mess :sob:

Will test with 2.4 and/or to shadow network.py.