Skip to content

Problems with "null" values: possibly return 0 or a default value? #76

@jeremyvisser

Description

@jeremyvisser

I am trying to scrape the JSON data feed off a hardware appliance with json_exporter, but the problem is that it sometimes returns a number, but other times returns null. This causes non-continuous metrics in Prometheus, which causes a cascade of difficulties.

The hardware appliance in question is an SMA Sunny Boy solar inverter, and I'm trying to avoid writing my own shim to ingest the data into Prometheus. The JSON it outputs looks roughly like (snipped for clarity):

{"result": { "0199-B3549FA1": {"6100_40263F00": {"1": [{"val": 1200}]}}}}

Using this config:

metrics:
- name: pv_power
  path: "{ .result..['6100_40263F00']..val }"

I get the sane value of:

pv_power 1200

However, when the sun sets, the solar inverter for some bizarre reason outputs null:

{"result": { "0199-B3549FA1": {"6100_40263F00": {"1": [{"val": null}]}}}}

This results in the metric becoming NaN:

pv_power NaN

And this makes it impossible to do certain formulas in Prometheus (e.g. calculating my house power (pv_power - grid_power_supplied) + grid_power_absorbed because when one of the metrics is missing, the entire calculation fails).

To avoid writing my own shim to parse the input JSON, I would need either NaN to be interpreted as 0, or have the ability to specify a default value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions