snmp_exporter drop metrics by metric value or label value

330 views
Skip to first unread message

Wang Yngwie

unread,
Oct 17, 2022, 3:01:08 AM10/17/22
to Prometheus Users
Hi, everyone. I want to drop some specific metrics by its value or its label value. For example:
1. the temperature metrics which values are 65535 meaning it's invalid
2. the power metrics which "entPhysicalClass" label vale are not "6" and "9"

I write the snmp.yml without generator, didn't find a specification of its syntax, does somebody know where it is?

Appreciate for any help :)

Brian Candler

unread,
Oct 17, 2022, 4:45:17 AM10/17/22
to Prometheus Users
> Hi, everyone. I want to drop some specific metrics by its value or its label value. For example:
> 1. the temperature metrics which values are 65535 meaning it's invalid
> 2. the power metrics which "entPhysicalClass" label vale are not "6" and "9"

Metric relabeling can be used to drop specific timeseries in the scrape response by label value, but not by metric value.

The only way I can think of dropping by metric value (without changing the exporter output) is to use a recording rule to make a modified version of the timeseries, e.g.

    expr: some_temperature != 65535

If you are happy to hack snmp.yml, you could try something like this (untested):

    regex_extracts:
      "":
      - value: NaN
        regex: ^65535$
      - value: $1
        regex: ^(.+)$


I don't know if it's allowed to use "NaN" as a value here: source code suggests it should work. However, a time series consisting of NaNs is not the same as an empty/missing timeseries. So depending on your requirements, it may be better to do

    regex_extracts:
      "":
      - value: INVALID
        regex: ^65535$
      - value: $1
        regex: ^(.+)$

although this will cause snmp_exporter to generate noisy logs at debug level.

Aside: if you look through the examples you can see regex being used to divide a value by 10 (or by 100), e.g.:

    regex_extracts:
      "":
      - value: $1.$2
        regex: ^(?:(.*)(.))$

> I write the snmp.yml without generator, didn't find a specification of its syntax, does somebody know where it is?


Having said that, you may just want to run the generator and look at its output to see what it emits :-)

Wang Yngwie

unread,
Oct 18, 2022, 2:48:06 AM10/18/22
to Prometheus Users
Thanks  Brain, for your help.

Brian Candler

unread,
Oct 18, 2022, 5:22:37 AM10/18/22
to Prometheus Users
Did it work? Which approach did you use?

Wang Yngwie

unread,
Oct 25, 2022, 10:36:47 PM10/25/22
to Prometheus Users
I have tried, but it didn't work, thank you all the same, maybe I should read the source code deeply.

Dmitry Abramov

unread,
Apr 4, 2024, 2:54:14 AM4/4/24
to Prometheus Users
Have you been able to figure out the problem? I have the same problem and would really like to find a solution. Thank you in advance!
Reply all
Reply to author
Forward
0 new messages