Telegraf doesn't work with custom timestamp [line protocol]

Using InfluxDB Cloud.
I have configured a telegraf agent to receive MQTT msgs and posting them to InfluxDB.
It works well when I don’t provide timestamp in the messages.
i.e. when messages are like below:

power,botid=bot1 p=2,pf=2
power,botid=bot1 p=3,pf=3

I can see those messages in the Influx Dashboard.
But when I try to use timestamp, I don’t see any errors from telegraf, however I don’t see the messages in the Influx DB graphs.
For example.

power,botid=bot1 p=2,pf=2 1575536708
power,botid=bot1 p=3,pf=3 1575536709

I tried the nanosecond version of timestamp, but it still didn’t work. What might be the issue?

Telegraf conf file for reference:

[global_tags]
[agent]
interval = “10s”
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = “0s”
flush_interval = “10s”
flush_jitter = “0s”
precision = “s”
debug = true
logfile = “/var/log/telegraf/abc”
[[outputs.influxdb_v2]]
urls = [“”]
token = “”
organization = “”
bucket = “mybucket”
[[inputs.mqtt_consumer]]
servers = [“tcp://127.0.0.1:1883”]
topics = [
“test”,
qos =2
username = “user”
password = “pass”
data_format = “influx”

So that timestamp is in seconds (it appears). If you convert that to nanoseconds, but don’t add enough zeros, 157553670800000000 it turns into GMT : Sunday, December 29, 1974 12:54:30.800 PM so that would be why you don’t see it in the dashboard. The nanosecond timestamp format would be 1575536708000000000 or GMT : Thursday, December 5, 2019 9:05:08 AM

I think you have a timestamp conversion problem. I recognize this because I do it all the time and wonder where my data is, when really it’s either way in the past, or in the future. :slight_smile:

dg

1 Like

Thanks, so much for your answer. I realize my mistake.
But I thought that specifying the agent interval to 10s would allow entries to be passed at the granularity of seconds. Isn’t that true? Is there any other option to send timestamp in seconds instead of nanoseconds?

Hi @Hemant_Shinde1,

The interval is the collection interval, what you’re after is the precision. Valid precisions are ns , us or µs , ms , and s . Set precision = 's' and you should be all set.

dg

1 Like

The agent precision option sets timestamp rounding for polling plugins, but doesn’t affect mqtt_consumer. If you decide to set it then make sure to include a scalar value too (precision="1s"). Timestamp format/units is a property of the data format and with line protocol it always uses nanoseconds.

There is one edge case where it is allowed to use a different precision in the influxdb_listener, but I highly recommend to skip it and always use nanosecond precision when writing line protocol.

1 Like

Thanks for clarification and the recommendation. I will follow that.