snmp_exporter add sysname as label

216 views
Skip to first unread message

Kordován Szabolcs

unread,
Nov 30, 2023, 1:40:24 PM11/30/23
to Prometheus Users
Hi,

Does somebody have a solution to add sysname as label to a metric?
Please share an example generator.yml.

Thanks,
Szabolcs

Brian Candler

unread,
Nov 30, 2023, 3:52:16 PM11/30/23
to Prometheus Users
In the sample generator.yml / snmp.yml in the "mikrotik" MIB, you can see how sysDescr is obtained; you should be able to get sysName in the same way. As shown, it is presented in its own separate metric, e.g.

    sysDescr{sysDescr="RouterOS RB4011iGS+"} 1

I can make use of this with a PromQL N:1 join. For example,

    rate(ifHCInOctets[2m])

becomes

    rate(ifHCInOctets[2m]) * on(instance) group_left(sysDescr) sysDescr

which gives the same results vector but with an extra sysDescr label (for those devices that have a corresponding sysDescr timeseries).

It would be conventional to put all the static information like sysName, sysDescr, sysLocation, sysObjectID, sysContact, sysServices into a single metadata metric, and then access it using similar queries. For more info see

Sorry, I don't have a ready-made snmp_exporter config to generate this metric for you - but if you do create it, please share, as it would be useful - or submit it as a PR for the sample config, now that snmp_exporter allows multiple modules to be polled for a single device. (I don't know why sysDescr is present only in the Mikrotik MIB, when it's generally useful).
 
If the question is "how can I put sysName as a distinct label on *all* the other metrics for a device?", then I don't know how or if it can be done, but I'd advise against it anyway: putting it all into a separate metric that you cross-reference avoids massive duplication of labels. Also, this metadata timeseries is a useful thing in itself: you can query it to find out how many devices have a particular sysObjectID or sysLocation, for example.
Reply all
Reply to author
Forward
0 new messages