snmp_exporter
snmp_exporter copied to clipboard
Generator: Allow metric label name and value rewrites
It would be nice to support label name and label value rewrites in the generator. AFAIC the snmp-exporter just uses the numeric OIDs to query the target and uses labelname value to emit the labelname. So the generator just needs to accept and pass it. The other nice to have is to be able to replace the values of a label.
E.g.:
# snmpbulkwalk -Lf /tmp/log -v 2c -c public -Pw -Pu -OX cisco_machine ciscoEnvMonTemperatureStatusTable
CISCO-ENVMON-MIB::ciscoEnvMonTemperatureStatusDescr[1006] = STRING: Switch#1, Sensor#1, Status is GREEN
CISCO-ENVMON-MIB::ciscoEnvMonTemperatureStatusValue[1006] = Gauge32: 27 degrees Celsius
CISCO-ENVMON-MIB::ciscoEnvMonTemperatureThreshold[1006] = INTEGER: 60 degrees Celsius
CISCO-ENVMON-MIB::ciscoEnvMonTemperatureLastShutdown[1006] = INTEGER: 0 degrees Celsius
CISCO-ENVMON-MIB::ciscoEnvMonTemperatureState[1006] = INTEGER: normal(1)
CISCO-ENVMON-MIB::ciscoEnvMonTemperatureStatusValueRev1[1006] = INTEGER: 27 degrees Celsius
The index number is not really something we wanna see, so we use the generator snippet:
lookups:
- source_indexes: [ciscoEnvMonTemperatureStatusIndex]
lookup: ciscoEnvMonTemperatureStatusDescr
drop_source_indexes: true
But this produces not what is desired either, because the description contains the current state of the sensor as well. E.g.:
ciscoEnvMonTemperatureLastShutdown{ciscoEnvMonTemperatureStatusDescr="Switch#1, Sensor#1, Status is GREEN "} 0
ciscoEnvMonTemperatureState{ciscoEnvMonTemperatureStatusDescr="Switch#1, Sensor#1, Status is GREEN "} 1
ciscoEnvMonTemperatureStatusValue{ciscoEnvMonTemperatureStatusDescr="Switch#1, Sensor#1, Status is GREEN "} 26
ciscoEnvMonTemperatureStatusValueRev1{ciscoEnvMonTemperatureStatusDescr="Switch#1, Sensor#1, Status is GREEN "} 26
ciscoEnvMonTemperatureThreshold{ciscoEnvMonTemperatureStatusDescr="Switch#1, Sensor#1, Status is GREEN "} 60
So having something like this would be nice:
lookups:
- source_indexes: [ciscoEnvMonTemperatureStatusIndex]
lookup: ciscoEnvMonTemperatureStatusDescr
- name: sensor
- regex: '(Switch#[0-9]+, Sensor#[0-9]+),.*'
- value: '$1'
drop_source_indexes: true
So that we finally get:
ciscoEnvMonTemperatureLastShutdown{sensor="Switch#1, Sensor#1"} 0
ciscoEnvMonTemperatureState{sensor="Switch#1, Sensor#1"} 1
ciscoEnvMonTemperatureStatusValue{sensor="Switch#1, Sensor#1"} 26
ciscoEnvMonTemperatureStatusValueRev1{sensor="Switch#1, Sensor#1"} 26
ciscoEnvMonTemperatureThreshold{sensor="Switch#1, Sensor#1"} 60
FWIW: Took a swing on it and ended up with https://github.com/jelmd/snmp_exporter/tree/lookup_label_rename and https://github.com/jelmd/snmp_exporter/tree/lookup_value_rename and our generator config file which makes use of it. For details see its documentation.
Hi,
are you planning on commiting the changes back into the main repository?
awesome work btw.
BR Takalele
Hi @Takalele,
Probably not. Diverged too much and obviously there is not much interest in it (and AFAICS, there is not really new stuff in > 0.20, which is worth the effort to merge it in?).
The exact problem as shown above can already be done with Prometheus metric_relabel_configs. It's not technically necessary in the exporter itself.
However, I see the value in having metric_relabel_configs functionality in the exporter itself. Since you can horizontally scale the exporter, it would allow you to take load off of Prometheus itself. It also makes it easier to ship pre-baked fixes.
My idea was to have this be a module-level feature.
I think this function is very good. I have encountered many problems like this. I want to merge multiple tables and insert labels into another table, but I cannot do it because the index is inconsistent.