Closed dngrudin closed 2 weeks ago
I suggest using the [xpath parser]() with
[[inputs.file]]
files = ["test_configs/jsontest_issue_15892.json"]
data_format = "xpath_json"
xpath_native_types = true
[[inputs.file.xpath]]
metric_name = "'pools'"
metric_selection = "/counters/thread/pools/*"
[inputs.file.xpath.fields_int]
active = "active"
[inputs.file.xpath.tags]
name = "name"
[[inputs.file.xpath]]
metric_name = "'errors'"
metric_selection = "/errors/type/error_list/*"
[inputs.file.xpath.fields_int]
count = "count"
[inputs.file.xpath.tags]
name = "name"
[[inputs.file.xpath]]
metric_name = "'errors'"
[inputs.file.xpath.fields_int]
count = "/errors/type/total_errors"
[inputs.file.xpath.tags]
name = "'total'"
which results in the following metrics (in line-protocol) for your example
> pools,host=Hugin,name=main active=1i 1727880774000000000
> errors,host=Hugin,name=SomeError count=3i 1727880774000000000
> errors,host=Hugin,name=total count=3i 1727880774000000000
Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Forums or provide additional details in this issue and reqeust that it be re-opened. Thank you!
Relevant telegraf.conf
Logs from Telegraf
System info
Telegraf 1.32.0-a0755797
Docker
No response
Steps to reproduce
./telegraf --once --config ./telegraf.conf
Expected behavior
Contents of metrics.prometheus file:
Actual behavior
Contents of metrics.prometheus file:
Additional info
The result of execution is affected by the offset within the parent element of the fields whose value must be found. With minimal change in input data, for example change the value from 3 to 30 the output result becomes correct. Modified input data:
Contents of metrics.prometheus file:
Presumably the problem is that the subPathResults variable may contain the results of parsing several objects. Later, when calling the existsInpathResults function, the data of another object corresponding to the specified index may be returned. Although an empty result should have been returned.
In my opinion, a possible solution could be to reset the subPathResults variable inside the processObjects function at each iteration cycle of the objects variable. Code snippet: