json-exporter icon indicating copy to clipboard operation
json-exporter copied to clipboard

Values could not be parsed to Float64

Open pete-leese opened this issue 7 years ago • 16 comments

I have set this up but struggling to get it return any data from my feed.

console output states the following:

2018/03/12 11:39:10 Found value 17.8

but when hitting the URL it just displays:

Values could not be parsed to Float64

The json I am trying to query is as follows: {
"isValid":true, "validationRuleErrors":[], "httpStatusCode":200, "genericErrorMessage":null, "data":{
"version":"17.8" } }

I am able to read httpStatusCode OK, however for other values such as isValid etc... this throws the same error.

Example query:

http://XXXX:9116/probe?target=http://XXXX.com/api/version/?json=%7B%22key%22:%22value%22&jsonpath=$.data.version

Secondly, is there a way to change the metric label from just outputting "value" to give each of the above json keys a unique identifier.

Any ideas ?

pete-leese avatar Mar 12 '18 11:03 pete-leese

To your second question, you can use this in your scrape config to overwrite the metric name (which is just a hidden label called __name__):


metric_relabel_configs:
      - source_labels: [__name__]
        regex: value
        target_label: __name__
        replacement: custom_metric_name

This overwrites "value" with "custom_metric_name".

SPFZ avatar Mar 17 '18 09:03 SPFZ

Thanks for that @spampel

If only it would work for me 😂 👍🏻

pete-leese avatar Mar 17 '18 17:03 pete-leese

I found the problem, it does not parse strings to float. There is a pull request (#1) fixing some of the problems with this exporter, including yours.

You can use this instead and it shoudl work: https://github.com/huiyiqun/json-exporter

I tested this and it should solve your problem.

SPFZ avatar Mar 18 '18 19:03 SPFZ

This is great to hear. Will get this installed and setup tomorrow. Thanks !

pete-leese avatar Mar 18 '18 20:03 pete-leese

Hi @SPZF, is there a method for querying more than one key from a single source that can be picked up by Prometheus or do I have to setup a url per metric I wish to digest from each json source?

pete-leese avatar Mar 18 '18 21:03 pete-leese

I've checked out https://github.com/huiyiqun/json-exporter and have gotten a bit further.

this is the json I am trying to pull metrics in ;

{ "isValid":true, "validationRuleErrors":[], "httpStatusCode":200, "genericErrorMessage":null, "data":{ "version":"17.8" } }

  • job_name: 'XXXX API - PROD' metrics_path: /probe params: jsonpath: [$.data.version] # Look for the version field jsonpath: [$.httpStatusCode] # Look for the version field static_configs:
    • targets:
      • http://xxxxx.co.uk/api/version/?json=%7B%22key%22:%22value%22%7D relabel_configs:
    • source_labels: [address] target_label: __param_target
    • source_labels: [__param_target] target_label: instance
    • target_label: address replacement: 127.0.0.1:9116 # Json exporter.

I was expecting this to create a new metric label per jsonpath but instead just have a duplicated metric label called "value".

Would like to be able to pre-fix each label with something that is unique;

I.E; version_value httpStatusCode_value

Does that make sense?

I am aware that there is a way to rename the metric but cannot see this working in this scenario?

Also - genericErrorMessage generates a "Values could not be parsed to Float64" error message when trying to scrape the value - suspect it is not handling the "null" value.

pete-leese avatar Mar 19 '18 12:03 pete-leese

@VR6Pete Can you post the exact response that you get as return? I might be able to assist you in transforming it in the metrics you want.

SPFZ avatar Mar 20 '18 11:03 SPFZ

Hi @SPFZ -

genericErrorMessage

2018/03/20 13:59:00 () could not be parsed to Float64

pete-leese avatar Mar 20 '18 14:03 pete-leese

@VR6Pete From what I understand from the code it does not support querying multiple values. This exporter does: https://github.com/kawamuray/prometheus-json-exporter

But you can only read one target and there are 3 open pull request.

If I had the time I would extend one of the exporters to support multiple targets and multi jsonpath' . The only limitation then would be the 2000 character limit for the get request from prometheus to the exporter.

SPFZ avatar Mar 20 '18 16:03 SPFZ

Thanks @SPFZ - I do actually use that exporter for a specific interface I wrote but as you say does not scale beyond that currently.

pete-leese avatar Mar 20 '18 17:03 pete-leese

@SPFZ or anyone else... Willing to put some funds to help push this forward?

Let me know if interested.

pete-leese avatar Apr 09 '18 20:04 pete-leese

@VR6Pete As said before I was not happy with any of the json exporters in existance, therefore I wrote an exporter specific to my problem in python.

SPFZ avatar Apr 10 '18 20:04 SPFZ

Is this available on github or are you able to share @SPFZ?

pete-leese avatar Apr 10 '18 21:04 pete-leese

It is company internal and specific to our problem, but writing an exporter is simple. A good starting tutorial can be found on Brian Brazils blog: https://www.robustperception.io/writing-json-exporters-in-python/

SPFZ avatar Apr 12 '18 11:04 SPFZ

Thanks for the reply, I just don’t have the time at the moment to learn python I’m afraid.

Still looking for some assistance with getting https://github.com/kawamuray/prometheus-json-exporter upto scratch.

pete-leese avatar Apr 25 '18 21:04 pete-leese

I have another scenario where the string cannot be converted.

json output;

{"version":"18.6.1.12"}

Console output:

2018/08/13 09:00:24 18.6.1.12(string) could not be parsed to Float64

Web UI ouput from probe results;

values is string but cannot be converted to Float64 ��� n���t�O�� ����K���Ϥ�.L�MW��DI)c����A]�!�|~S��[L����)�h�wB�}/�QL�F^���#e-"�k=�=9���T���m�B�R'�Z�$C"��29�,#��9�x-���G��/.�o�.�o�i�>�KNf��������`ԩ:��

Just to confirm I am running the branched version SPFZ posted earlier on in this discussion.

pete-leese avatar Aug 13 '18 09:08 pete-leese