json_exporter
json_exporter copied to clipboard
jsonpath for length of an array
Is there a way to get length of an array?
Example:
- name: active_values_count
type: object
path: $.values[*]?(@.state == "ACTIVE").length()
Hi, I think the path defines element selection for the filter. The length or the array does not help you with element selection. You have it in inappropriate place. Maybe you can use in label or value.
Is this still an issue? It seems solved.
It is still an issue and it won't be resolved unless the collector is re-written to use a jsonpath module that supports the .length()
method, or if kubernetes implements it (since we use their jsonpath module):
https://github.com/prometheus-community/json_exporter/blob/1614ee8d771f89a8c6093aee9985609c69b37532/exporter/collector.go#L23
This is also an issue for accessing specific elements. I can't do
$[(@.length - 2)]
for instance