Skip to content

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

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

Open
jeremyvisser opened this issue Jan 30, 2021 · 3 comments
Open
Labels

Comments

@jeremyvisser
Copy link

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.

@rustycl0ck
Copy link
Member

Having an option to specify a default value for null seems reasonable to me. Maybe we can have something like replace_null_with: option for each metric. The default can remain NaN, but can be overridden for specific metrics if needed. If you can send a PR, I can review it.

@SuperQ
Copy link
Contributor

SuperQ commented Feb 15, 2021

From a Prometheus best practice, null data should be dropped/ignored. Using NaN for null is not recomended.

@rustycl0ck
Copy link
Member

Thanks @SuperQ , I see how replacing null data with a zero or NaN or any other value can lead to wrong calculations later (like if we replace null with a zero, the calculation of average for this data would then shift towards zero which would be incorrect). I guess it is a bug in the current version of this exporter then.

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

No branches or pull requests

3 participants