Prometheus Extenstion: Add option to prefix metric labels with a user-configured string

Hi,

I intend to submit a PR to modify the Prometheus extension. Creating this post to track progress.

Currently the LibreNMS Prometheus extension will write metrics via Prometheus PushGateway with label names based on the source data in LibreNMS. For instance it will write metrics with labels like this for data sourced from the SNMP IF-MIB:

OUTUCASTPKTS
ifOutUcastPkts_rate
INOCTETS
ifInErrors_rate

This is fine and the metric export works as expected. The Prometheus guidelines for metric names, however, state that they “should have a (single-word) application prefix relevant to the domain the metric belongs to”: Metric and label naming | Prometheus

Currently the LibreNMS Prometheus extension does not confirm to this guideline. This leads to a less-than-ideal result in our environment. We have data from many different sources in our Prometheus database, and the source of every metric is easily identifiable from the metric names. For instance:

atlas_ping_avg_latency
bird_protocol_prefix_filter_count
exim_smtp_errors_total
nginx_vts_server_requests_total
squid_server_all_errors_total

Ideally the metrics exported from LibeNMS would have a similar prefix on them (‘librenms’ for instance), to aid grouping and discovery. It would also prevent any potential namespace collision with other data sources which might omit to use an source-specific prefix.

To give a practical example, it would be useful if the example metrics I gave were instead written to Prometheus like this:

librenms_OUTUCASTPKTS
librenms_ifOutUcastPkts_rate
librenms_INOCTETS
librenms_ifInErrors_rate

My proposal would be to add another configurable option to add a prefix if so desired:

$config['prometheus']['prefix'] = 'librenms'; # Optional

This should be optional, and default to an empty string if not specified. Which should ensure backwards-compatibility.

I welcome and comments or feedback, I am currently prepping my git environment and will submit the PR as soon as that is ready.

thanks,

Cathal.

1 Like

PR submitted: https://github.com/librenms/librenms/pull/13272

1 Like

This PR was accepted and merged :smiley:

Big thanks to @murrant / Tony Murray for assisting me with the code and merging!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.