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
https://www.robustperception.io/how-to-have-labels-for-machine-roles
https://www.robustperception.io/exposing-the-software-version-to-prometheus
https://www.robustperception.io/left-joins-in-promql
https://prometheus.io/docs/prometheus/latest/querying/operators/#many-to-one-and-one-to-many-vector-matches

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.

On Thursday, 30 November 2023 at 18:40:24 UTC Kordován Szabolcs wrote:

> Hi,
>
> Does somebody have a solution to add sysname as label to a metric?
> Please share an example generator.yml.
>
> Thanks,
> Szabolcs
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/a0e2cb19-2fef-4336-a9cd-e30d89c62361n%40googlegroups.com.

Reply via email to