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

Json #71

Open
leomargontier opened this issue Sep 15, 2023 · 2 comments
Open

Json #71

leomargontier opened this issue Sep 15, 2023 · 2 comments

Comments

@leomargontier
Copy link

How to manage a json metric (device, value, timestamp) ?

@poggenpower
Copy link
Collaborator

@leomargontier sorry for the late reply.

I typically use regex to parse out.

e.g to get the uptime from a tasmota TELE/State:

{"Time":"2023-11-01T11:02:36","Uptime":"44T11:20:54","UptimeSec":3842454,"Heap":100,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":28,"Berry":{"HeapUsed":14,"Objects":293},"POWER1":"OFF","POWER2":"OFF","POWER3":"ON","POWER4":"OFF","POWER5":"OFF","Wifi":{"AP":1,"SSId":"iot","BSSId":"D0:21:F9:E6:2C:FD","Channel":1,"Mode":"11n","RSSI":94,"Signal":-53,"LinkCount":1,"Downtime":"0T00:00:03"}}

I am using:

  - name: "tasmota_uptimesec"
    help: "Tasmota uptime in seconds"
    type: "gauge"
    topic: "esp/+/tele/STATE" # this topic may contain several results
    label_configs:
      - source_labels:  ['__value__']
        action:         'keep'
        regex:          '.*"UptimeSec":([-]?[0-9]+)'
      - source_labels:  ['__msg_topic__']
        target_label:   '__topic__'
      - source_labels:  ['__msg_topic__']
        target_label:   'controller'
        regex:          'esp/([a-zA-Z0-9]+)/tele/STATE'
        replacement:    '\1'
        action:         'replace'
      - source_labels: ['__value__']
        target_label:   '__value__'
        regex:          '.*"UptimeSec":([-]?[0-9]+).*'
        replacement:    '\1'
        action:         'replace'

I know this looks more like a workaround, but working well. Have some build in json parser would be nice, but it is not there.
PRs are welcome ;-)

@poggenpower
Copy link
Collaborator

Ahh I saw you did a PR, thanks! Would you mind to create an example with explaining comment. and PR 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