prometheus-community/json_exporter

how to compute value if missing from other 2 values

gmoscalu opened this issue · 1 comments

Hi there,

I am using JSON_Exporter to monitor some Shelly EM devices (power usage monitoring).

I have configured them allright, but Shelly 3EM provides :

"emeters": [
    {
        "power": 7.81,
        "pf": 0.79,
        "current": 0.04,
        "voltage": 235.16,
        "is_valid": true,
        "total": 142226.2,
        "total_returned": 0.0
    },

while Shelly EM provides only:

"emeters": [
    {
        "power": 0.00,
        "reactive": 0.00,
        "pf": 0.00,
        "voltage": 237.77,
        "is_valid": true,
        "total": 0.0,
        "total_returned": 0.0
    },

As you can see the "current" is missing from the EM output, but since we have the "power" & "voltage" i could be computing it when it's missing, if only i could figure out how to.

My JSON_Explorer config looks like this:

shelly3em:
metrics:
- name: shelly3em
type: object
path: '{ .emeters[0] }'
help: Shelly SmartMeter Data
labels:
device_type: 'Shelly_PM'
phase: 'Phase_1'
values:
Instant_Power: '{.power}'
Instant_Current: '{.current}'
Instant_Voltage: '{.voltage}'
Instant_PowerFactor: '{.pf}'
Energy_Consumed: '{.total}'
Energy_Produced: '{.total_returned}'

Can anyone help:

  • check if ".current" is empty/null
  • if "power" & "voltage" are present in the JSON, compute the current=power / voltage

Thanks in advance,
Gabriel

It's probably not ideal, but could you not get metrics for power and voltage and calculate the voltage on the query side?