I have a json object like this:
Is it possible, to push various key / value pairs to influxdb in one input plugin.For example
a
c
f
Many thanks
I have a json object like this:
Is it possible, to push various key / value pairs to influxdb in one input plugin.For example
a
c
f
Many thanks
I made a few assumptions about the input: that you wanted the strings to be tags and that f
was an numeric value, and that there would only be one f
in the d
list. If your actual data is too much more complicated, it may not work out.
{
"a": "v",
"b": {
"c": "v"
},
"d": [
{
"e": 3
},
{
"f": 4
}
]
}
Anyway I came up with this, rather crazy, query:
[[inputs.file]]
files = ["example.json"]
tag_keys = ["a", "c"]
json_query = '{a,b.c,d|#(f!="")#|0.f}'
data_format = "json"
file,a=v,c=v f=4 1584586995000000000
Thank you!
Do I have to define the fields which are not numbers, as string_fields?
What about, a “dot” in the key name, do I have to escape it?
My config:
[[inputs.http]]
urls = [“url”]
method = “POST”
body = ‘{“identity”: “x”}’
interval = “30s”
success_status_codes = [200]
data_format = “json”
tag_keys = [“IMSI”]
json_query = ‘{mme, subscriber.IMSI}’
timeout= “10s”
headers = {“Content-Type” = “application/json”}
[inputs.http.tags]
influxdb_database = “subscriber_data”
My data:
{
“mme”: “MME88”,
“subscriber”: {
“IMSI”: “x”
}
}
Do I have to define the fields which are not numbers, as string_fields?
Yes, but you can use a glob: json_string_fields = ["*"]
What about, a “dot” in the key name, do I have to escape it?
Should be possible to escape a dot with backslash, the full syntax for json_query
is described here: gjson/SYNTAX.md at master · tidwall/gjson · GitHub
Got it working, I’m now pushing the whole data into influxdb.
Thank you!