How to convert the String obtained by the snmp exporter into gauge

758 views
Skip to first unread message

New user

unread,
Nov 22, 2023, 6:56:01 AM11/22/23
to Prometheus Users
Hi! This problem is not complicated, but it has been bothering me for a long time. I hope you can help me! I currently have a network device that needs to be monitored. I need to use the snmp exporter to obtain metrics and send them to Prometheus. However, several  metrics   of this device return Strings to snmp protocol. In order to obtain the correct results, I can only set the type to DisplayString in the override in generator.yml:
overrides: runningStatus: type: DisplayString
Now I have two metrics:
① Running Status:
There only two values: "true" and "false". The snmp exporter will moniter this metric and return:
runningStatus{runningStatus="true"} 1

② Success Rate:
It is a float value actually. The snmp exporter will moniter this metric and return:
successRate{successRate="100.0"} 1

As can be seen, the value we want has been placed in the label, and the metric has been returned with a meaningless 1 (at the end). However, what I hope is that the 1 at the far right end can be the metric I want, because in the existing monitoring system we are running, those metrics needs to be saved to the system. On Prometheus, the values displayed in this way can only be placed in labels, and the label values are not convenient for statistical analysis. 

I hope to associate false with 0, true with 1, and present it in gauge in ①. In ②, change the numerical value displayed as a String type to gauge.

The most common methods I have found are the relabel in Prometheus.yml. But most of them only change the name of the Label using regularization, which cannot achieve the desired effect.

There is a very similar question description, but its solution doesn't work for me:

The method of this url will make it impossible for me to directly monitor the metric! I cannot see the metric in the localhost:9116 following its attempts.

I am a new user and need to add several monitoring metrics to a running Prometheus + snmp exporter. This means that I cannot easily change the system version or settings. The version of snmp is 0.20.0, prometheus is 2.6.0.

Thank you very much for your answer!

Brian Candler

unread,
Nov 22, 2023, 7:29:35 AM11/22/23
to Prometheus Users
"There is a very similar question description, but its solution doesn't work for me:
That's exactly the solution you need (it even shows how to convert string values like 'on' and 'off' to 1 and 0), so please be more specific about your problem and in what way it "doesn't work".

* say what version of snmp_exporter/generator you're running
* show your generator.yml that you wrote which includes regex_extracts
* show the snmp.yml that it generated
* show the metrics you are getting back from snmp_exporter, and explain in what way they are not what you expect or need
* show what snmpwalk gives over the same OID
* if you can, provide the link to the MIB file(s) needed to understand the MIB structure and convert your generator.yml

You can find some examples of how to use regex_extracts here:

Brian Candler

unread,
Nov 22, 2023, 7:33:11 AM11/22/23
to Prometheus Users
Sorry, I see you already posted your snmp_exporter version (0.20.0).  regex_extracts has been around since 2017 so you should have it.

It doesn't do any harm to try a newer version of snmp_exporter, but beware that in v0.23.0 the config file format changed, separating out "modules" and "auths".

Reply all
Reply to author
Forward
0 new messages