mqtt_exporter
mqtt_exporter copied to clipboard
'Incorrect label' error when extracting value AND additional attribute from __value__
Hello,
I came across this project and it's great. It's exactly what I need for my project in which I'm receiving json messages over MQTT.
The problem I'm facing, is that I cannot extract any additional attributes on top of the numeric value. For simplicity of the example let's imagine my MQTT data looks like this
someAttribute=A;val=123
(in reality it's json but this regex will be simpler)
This works:
metrics:
- name: 'example'
help: 'help text'
type: 'counter'
topic: 'topics/+'
label_configs:
- source_labels: ['__value__']
regex: '.*val=(.*)'
target_label: '__value__'
replacement: '\1'
action: 'replace'
This doesn't work:
metrics:
- name: 'example'
help: 'help text'
type: 'counter'
topic: 'topics/+'
label_configs:
- source_labels: ['__value__']
regex: '.*someAttribute=(.*);.*'
target_label: 'attributeLabel'
replacement: '\1'
action: 'replace'
- source_labels: ['__value__']
regex: '.*val=(.*)'
target_label: '__value__'
replacement: '\1'
action: 'replace'
and I get
File "C:\k\temp\git_projects\mqtt_exporter\mqtt_exporter.py", line 384, in _export_to_prometheus
prometheus_metric.update(label_values, value)
File "C:\k\temp\git_projects\mqtt_exporter\mqtt_exporter.py", line 450, in update
child = self.metric.labels(*label_values)
File "C:\Users\toadc\AppData\Local\Programs\Python\Python310\lib\site-packages\prometheus_client\metrics.py", line 164, in labels
raise ValueError('Incorrect label count')
even though, I can see in the debug logs that the conversion was successful
Hi, thanks for pointing this out. I'll try to look into it …