Extracting multiple metrics from SNMP string

37 views
Skip to first unread message

Elliott Balsley

unread,
Mar 26, 2025, 4:44:49 AMMar 26
to Prometheus Users
I have an SNMP device that returns a value like this:

DOLBY-CP850-MIB::cp850MeterLevels.0 = STRING: "00 00 00 00 00 00 00 00 00 00"

This string represents the volume level of 10 separate audio channels, so I would like to break it apart and record it as 10 metrics.  I previously had this working in Telegraf so the result looked like this:
snmp_dolby_cp_meter_level_dbfs{channel="L"} 0
snmp_dolby_cp_meter_level_dbfs{channel="R"} 0
snmp_dolby_cp_meter_level_dbfs{channel="C"} 0
snmp_dolby_cp_meter_level_dbfs{channel="LFE"} 0
snmp_dolby_cp_meter_level_dbfs{channel="Lss"} 0
snmp_dolby_cp_meter_level_dbfs{channel="Rss"} 0
snmp_dolby_cp_meter_level_dbfs{channel="Lrs"} 0
snmp_dolby_cp_meter_level_dbfs{channel="Rrs"} 0
snmp_dolby_cp_meter_level_dbfs{channel="Lts"} 0
snmp_dolby_cp_meter_level_dbfs{channel="Rts"} 0

Is this possible to do with snmp-exporter?  I couldn't find any way to add the channel label.  The best I could think of is this regex_extract in the exporter, but this isn't really what I want because it adds the channel identifier to the metric name.

      cp850MeterLevels:
        type: DisplayString
        regex_extracts:
          '_L':
          - regex: '(..) .. .. .. .. .. .. .. .. ..'
            value: $1
          '_R':
          - regex: '.. (..) .. .. .. .. .. .. .. ..'
            value: $1
          '_C':
          - regex: '.. .. (..) .. .. .. .. .. .. ..'
            value: $1
          '_LFE':
          - regex: '.. .. .. (..) .. .. .. .. .. ..'
            value: $1
          '_Lss':
          - regex: '.. .. .. .. (..) .. .. .. .. ..'
            value: $1
          '_Rss':
          - regex: '.. .. .. .. .. (..) .. .. .. ..'
            value: $1
          '_Lrs':
          - regex: '.. .. .. .. .. .. (..) .. .. ..'
            value: $1
          '_Rrs':
          - regex: '.. .. .. .. .. .. .. (..) .. ..'
            value: $1
          '_Lts':
          - regex: '.. .. .. .. .. .. .. .. (..) ..'
            value: $1
          '_Rts':
          - regex: '.. .. .. .. .. .. .. .. .. (..)'
            value: $1

Brian Candler

unread,
Mar 26, 2025, 5:06:57 AMMar 26
to Prometheus Users
I don't think the exporter can do that, although it sounds like a good idea to me (i.e. to be able to set a label rather than mangle the metric name).

Possibly you could use metric_relabel_configs to fix it up:

- source_labels: [__name__]
  regex: '.*_CHANNEL_(.+)'
  target_label: channel
- source_labels: [__name__]
  regex: '(.*)_CHANNEL_.+'
  target_label: __name__

Otherwise, a simple HTTP proxy which sits between prometheus and snmp_exporter.

Elliott Balsley

unread,
Apr 1, 2025, 7:00:36 PMApr 1
to Prometheus Users
Thanks, that relabel config works perfectly!
Reply all
Reply to author
Forward
0 new messages