Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Incorrect label' error when extracting value AND additional attribute from __value__ #52

Open
code77 opened this issue Oct 22, 2022 · 1 comment

Comments

@code77
Copy link

code77 commented Oct 22, 2022

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

@fhemberger
Copy link
Owner

Hi, thanks for pointing this out. I'll try to look into it …

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants