Skip to content
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

Error gettting values when number is between quotes (string) #2

Open
viper0131 opened this issue Jan 21, 2018 · 3 comments
Open

Error gettting values when number is between quotes (string) #2

viper0131 opened this issue Jan 21, 2018 · 3 comments

Comments

@viper0131
Copy link

viper0131 commented Jan 21, 2018

Hi,

I'm trying to parse a json object that contains:
"NumberOfUsers":"30"

The number is between quotes. I can't change it, it an off the shelf app that generates this json.

In example.yaml I have the following metrics definition:

- name: NumberOfUsers
  description: Number of users
  path: $.NumberOfUsers

When I curl the endpoint it throws the following error:

2018-01-21 15:58:35,551 - root - DEBUG - metric_name: test_NumberOfUsers, value for '$.NumberOfUsers'
2018-01-21 15:58:35,551 - root - DEBUG - metric_name: test_NumberOfUsers, value for '$.NumberOfUsers' : 30
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/SocketServer.py", line 596, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/local/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/SocketServer.py", line 652, in __init__
    self.handle()
  File "/usr/local/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/local/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
    method()
  File "/usr/local/lib/python2.7/site-packages/prometheus_client/exposition.py", line 94, in do_GET
    output = generate_latest(registry)
  File "/usr/local/lib/python2.7/site-packages/prometheus_client/exposition.py", line 80, in generate_latest
    output.append('{0}{1} {2}\n'.format(name, labelstr, core._floatToGoString(value)))
  File "/usr/local/lib/python2.7/site-packages/prometheus_client/core.py", line 823, in _floatToGoString
    elif math.isnan(d):
TypeError: a float is required

@viper0131
Copy link
Author

I quick workaround seems to work:

In app/exporter.py:

metric = GaugeMetricFamily(metric_name, metric_description, value=float(value))
works for now.

@bcg62
Copy link

bcg62 commented Dec 10, 2019

I'm also hitting this issue

@kunchalavikram1427
Copy link

Hi, I also face this issue now

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

No branches or pull requests

3 participants