Issue in json parsing by telegraf while json seems fine

telegraf

#1

Hello,
I’ve written a bash script that launch a “df -k” command and send its result to influx database after some treatment in the shell script. The result is like this (several more blocks of data) :
[
{
“fs”: “/dev/mapper/vgapp01-lvsavcatnbu”,
“mount”: “/catalog_save_nbu”,
“sia”: “TEC”,
“total”: 33538048,
“utilise”: 33538028
},
{
“fs”: “tmpfs”,
“mount”: “/run/user/0”,
“sia”: “TEC”,
“total”: 13158864,
“utilise”: 0
}
]

Note : the display of this example is wrong here : the path in the “fs” field has a \ before all /

But the data isn’t sent to influx db and I can se following error message in telegraf.log :
E! Error in plugin [inputs.exec]: unable to parse out as JSON, json: cannot unmarshal array into Go value of type map[string]interface {}

I’ve tested the json format and it seems very fine (tested in jason validator tools).

I don’t understand, if you have any idea, i thank you in advance.


#2

I have been having the same issue.

When I run ‘systemctl status telegraf’ in the terminal of my AWS instance, I see an error: “json: cannot unmarshal string into Go struct field event.data of type particle.data” (I’m trying to publish data from Particle through a webhook)

For me, I can see the telegraf.go code on github for the Particle. The event struct and data struct look like this:

type event struct {
Name string json:"event"
Data data json:"data"
TTL int json:"ttl"
PublishedAt string json:"published_at"
Database string json:"measurement"
}

type data struct {
Tags map[string]string json:"tags"
Fields map[string]interface{} json:"values"
}

I think telegraf can’t parse the JSON I’m sending it into a map in the data struct.

I’m trying to figure out why my JSON parsing is not working, but perhaps searching github for the telegraf Go code might help?

In the case that you have figured this out, could you provide some tips to get it working?


#3

@pique can you paste an example payload that Particle outputs to telegraf, it may shed some light as to why the unmarshaling is failing.


#4

@Ghorin if you are still seeing that cannot unmarshal array into Go value error, can you change the output of your script to something like the following?

{
  "/dev/mapper/vgapp01-lvsavcatnbu": {
    "fs": "/dev/mapper/vgapp01-lvsavcatnbu",
    "mount": "/catalog_save_nbu",
    "sia": "TEC",
    "total": 33538048,
    "utilise": 33538028
  },
  "tmpfs": {
    "fs": "tmpfs",
    "mount": "/run/user/0",
    "sia": "TEC",
    "total": 13158864,
    "utilise": 0
  }
}

Here is an example of what is happening when you get that error.


#5

@glinton I’m publishing this data from Particle to Telegraf:


{"data":"{ \"tags\" : {\"id\": \"test\", \"location\": \"myLoc\"}, \"values\": {\"capacity\": 10}}","ttl":60,"published_at":"2018-06-26T22:36:24.431Z","coreid":"3c0038000c47363433353735","name":"capacity"}


#6

Sorry for the delayed response. You’ll need to remove the quotes around data's value so it looks like this:

{"data": {"tags" : {"id": "test", "location": "myLoc"}, "values": {"capacity": 10}},"ttl":60,"published_at":"2018-06-26T22:36:24.431Z","coreid":"3c0038000c47363433353735","name":"capacity"}

See in playground.