json_exporter
json_exporter copied to clipboard
jsonpath filter for root level key-value
Hi, i got some problem when trying to use jsonpath filter in root level key-value.
what i want: for the example json:
{
"status": "running"
}
if status == "running"
, set static metric = 1
if status == "stopped"
, set static metric = 0
my config.yml:
metrics:
- name: test
type: object
path: '{$.[?($.status=="running")]}'
help: test
labels:
label: test
values:
active: 1
- name: test
type: object
path: '{$.[?($.status=="stopped")]}'
help: test
labels:
label: test
values:
active: 0
what did i see
http://localhost:7979/probe?target=http://host.docker.internal:8000/status.json
returns me nothing but white screen,
and get following error in console
level=error ts=2021-05-27T11:28:23.049Z caller=collector.go:128 msg="Failed to execute jsonpath" err=" is not found" path="{$.[?($.status==\"running\")]}" data="{\n \"status\":\"running\"\n}"
level=error ts=2021-05-27T11:28:23.050Z caller=collector.go:69 msg="Failed to extract json objects for metric" err=" is not found" metric="Desc{fqName: \"test_active\", help: \"test\", constLabels: {}, variableLabels: [label]}"
level=error ts=2021-05-27T11:28:23.050Z caller=collector.go:128 msg="Failed to execute jsonpath" err=" is not found" path="{$.[?($.status==\"stopped\")]}" data="{\n \"status\":\"running\"\n}"
level=error ts=2021-05-27T11:28:23.050Z caller=collector.go:69 msg="Failed to extract json objects for metric" err=" is not found" metric="Desc{fqName: \"test_active\", help: \"test\", constLabels: {}, variableLabels: [label]}"
other info
the path $.[?($.status=="running")]
was tested successfully in https://jsonpath.herokuapp.com/,
but failed in https://jsonpath.com/.
and i also tried other path like .[?($.status=="running")]
, .[?(@.status=="running")]
, and $.[?(@.status=="running")]
but none of them working but got the same error message.
looking for your help and thanks in advance
Try this:
'{$[?(@.status=="running")]}'
Try this:
'{$[?(@.status=="running")]}'
thanks for your reply, but it's not working. and the error message doesn't change as well
level=error ts=2021-06-08T03:28:16.722Z caller=collector.go:128 msg="Failed to execute jsonpath" err="map[status:running] is not array or slice and cannot be filtered" path="{$[?(@.status==\"running\")]}" data="{\n \"status\": \"running\"\n}\n"
level=error ts=2021-06-08T03:28:16.723Z caller=collector.go:69 msg="Failed to extract json objects for metric" err="map[status:running] is not array or slice and cannot be filtered" metric="Desc{fqName: \"test_active\", help: \"test\", constLabels: {}, variableLabels: [label]}"
level=error ts=2021-06-08T03:28:16.723Z caller=collector.go:128 msg="Failed to execute jsonpath" err="map[status:running] is not array or slice and cannot be filtered" path="{$[?(@.status==\"stopped\")]}" data="{\n \"status\": \"running\"\n}\n"
level=error ts=2021-06-08T03:28:16.723Z caller=collector.go:69 msg="Failed to extract json objects for metric" err="map[status:running] is not array or slice and cannot be filtered" metric="Desc{fqName: \"test_active\", help: \"test\", constLabels: {}, variableLabels: [label]}"
@kunkka234
I had the same issue today, no solution after 1 hour of struggling. Did you find a way to solve this ?
+1 Also having this issue
+1 The same issue.
+1 The same issue.
+1 The same issue.
+1 The same issue.
anyone find the answer to this? Wasn't able to figure it out :(
+1 The same issue.
Anyone has been able to figure this out yet?
Any updates here?
Given the same example.json
{
"status": "running"
}
I was able to extract status and apply it as label as suggested here
My config.yml
looks like this:
---
modules:
health:
metrics:
- name: service_status
type: object
help: Service Status
path: '{$}'
labels:
status: '{ .status }'
values:
availability: 1
To the root path in JSONPath is '{$}'
+1 The same issue here. Solution shown above is looking at list structure, not nested objects, which seems to be the main issue for the json-exporter
+1 The same issue.
+1
+1
+1 same here