tolleiv / json-exporter

Prometheus exporter which fetches JSON from a URL and exports one of the values as gauge metrics
24 stars 18 forks source link

Values could not be parsed to Float64 #3

Open pete-leese opened 6 years ago

pete-leese commented 6 years ago

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 ?

SPFZ commented 6 years ago

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".

pete-leese commented 6 years ago

Thanks for that @spampel

If only it would work for me 😂 👍🏻

SPFZ commented 6 years ago

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.

pete-leese commented 6 years ago

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

pete-leese commented 6 years ago

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 commented 6 years ago

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" } }

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.

SPFZ commented 6 years ago

@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.

pete-leese commented 6 years ago

Hi @SPFZ -

genericErrorMessage

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

SPFZ commented 6 years ago

@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.

pete-leese commented 6 years ago

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 commented 6 years ago

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

Let me know if interested.

SPFZ commented 6 years ago

@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.

pete-leese commented 6 years ago

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

SPFZ commented 6 years ago

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/

pete-leese commented 6 years ago

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 commented 6 years ago

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.