Some Bits: Nelson's log

telegraf vs timestamp precision

Learned something the hard way: telegraf by default rounds (some?) timestamps to 1 second.

I’ve got some code that runs IRTT and emits influx format lines every 100ms with precise timings and timestamps. Output like this:

irtt_packets,remote_address=45.66.249.240:2112 delay_rtt=49890590,ipdv_rtt=-25723094 1683647662430925080
irtt_packets,remote_address=45.66.249.240:2112 delay_rtt=100696672,ipdv_rtt=50806082 1683647662530279079
irtt_packets,remote_address=45.66.249.240:2112 delay_rtt=66017146,ipdv_rtt=-34679526 1683647662630672054
irtt_packets,remote_address=45.66.249.240:2112 delay_rtt=56583224,ipdv_rtt=-9433922 1683647662731135862

Those are nanosecond timestamps and the interval is roughly 100,000,000 nanoseconds (ie: 0.1 seconds).

But in influx the data comes out looking like this:

1683646020000000000 43842340 gvl 12180311 45.66.249.240:2112
1683646021000000000 43708652 gvl -11768007 45.66.249.240:2112
1683646022000000000 36362863 gvl -4289225 45.66.249.240:2112
1683646023000000000 40232640 gvl -47825 45.66.249.240:2112

It’s filed all the numbers off my timestamps! Worse, it’s combined ten 100ms measurements into a single 1s measurement. I think new entries just clobber old ones although I’m seeing some signs of it actually combining data from several measurements (‽)

The culprit is precision in telegraf.conf. This can be set both for the whole agent and on a per-input plugin. Maybe also per-output.

My Ubuntu had this set to the empty string. What that means is not well documented on the website but the .conf file had this helpful comment

## By default or when set to "0s", precision will be set to the same
## timestamp order as the collection interval, with the maximum being 1s.
## ie, when interval = "10s", precision will be "1s"
## when interval = "250ms", precision will be "1ms"

So that’s super confusing. But I had my interval at 15s and was seeing timestamps with precision of 1s. I added a precision = "1ns" to the input of interest and now it’s logging timestamps properly.

I can see how truncating timestamps like this could be useful; it hides slight jitter in data and everything lines up neatly. But in my case I really need precise timings. Also the way this causes multiple entries to be lost (because of timestamp combining in influx) is bad. Particularly surprised that it’d throw away precise timestamp info from influx wire format data. If someone went through the trouble to output nanoseconds they probably meant to.