telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

tcp socket does not send message after write immediately

Open gaurav-moonfroglabs opened this issue 10 years ago • 2 comments

I have tcp client configured in my code and sending stats to telegraf. But the telegraf service on tcp recieved messages after connection close. And they are batching the data till then and giving error in json parsing eg:

Malformed packet: [{"hostName":"172.16.0.145","id":"redshift","test":100}{"hostName":"172.16.0.145","id":"redshift","test":100}{"hostName":"172.16.0.145","id":"redshift","test":100}{"hostName":"172.16.0.145","id":"redshift","test":100}], Error: unable to parse out as JSON, invalid character '{' after top-level value

gaurav-moonfroglabs avatar May 06 '16 13:05 gaurav-moonfroglabs

Your tcp client should be breaking up multiple packets on newlines, I don't think this is telegraf's problem.

sparrc avatar May 06 '16 14:05 sparrc

Actually we are not splitting newlines on JSON input. I don't think we can split newlines, since JSON allows for newlines within the same object. ie, if we split on newlines then users sending this:

{
    "a": 5,
    "b": {
        "c": 6
    },
    "mytag": "foobar",
    "othertag": "baz"
}

would get failures.

Telegraf is not doing the aggregating. You need to have your tcp client send separate packets for each json object.

sparrc avatar May 06 '16 15:05 sparrc