json_exporter icon indicating copy to clipboard operation
json_exporter copied to clipboard

Failed to convert extracted value to float64

Open jhoustek23 opened this issue 3 years ago • 2 comments

my json looks like:

{
  "execution_status": {
    "status": "ok",
    "last_execution_date": "2021-11-19T09:14:47.819Z"
  }
}

and config.yml:

---
metrics:
- name: status
  type: value
  path: "{.execution_status.status}"

result is:

ts=2021-11-19T09:21:51.263Z caller=level.go:63 level=error msg="Failed to convert extracted value to float64" path={.execution_status.status} value=ok err="strconv.ParseFloat: parsing \"ok\": invalid syntax; strconv.ParseFloat: parsing \"ok\": invalid syntax" metric="Desc{fqName: \"status\", help: \"status\", constLabels: {}, variableLabels: []}"

What am I doing wrong? Thanks!

jhoustek23 avatar Nov 19 '21 09:11 jhoustek23

@jhoustek23 The exporter tries to map "ok" to a number, this is obviously not working

in order to get a string out you have to use it as a label, e.g.:

metrics:
- name: execution_status
  type: object
  path: "{.execution_status}"
  labels:
    status: '{.status}'
  values:
    status: 1

This should result in the following metrics:

execution_status{staus="ok"} 1

david-loe avatar Nov 23 '21 14:11 david-loe

thank you! its working

jhoustek23 avatar Nov 23 '21 14:11 jhoustek23

Another solution for this can be found here - https://github.com/prometheus-community/json_exporter/issues/186#issuecomment-1328156005. I will close this issue since it has already been resolved for OP.

rustycl0ck avatar Nov 30 '22 10:11 rustycl0ck