MQTT Plugin - I need time of arrival and JSON payload timestamp

I’m picking up data from MQTT in JSON format via Telegraf and forwarding it on to some InfluxDB databases.

My input JSON has a timestamp encoded in it as a parameter which I need to have in the Line Protocol I forward on so I use json_time_key. Unfortunately for a journal I’m also creating in a separate database I’d also like the time of arrival of the data from MQTT (this seems to be not available as json_time_key sets the timestamp to the JSON payload).

Does anyone have any ideas how I can get both, ideally as the JSON payload timestamp as my Line Protocol timestamp and the time of arrival timestamp as a value?

Or even, as I can get the time-of-arrival as a timestamp and the other timestamp as a value in my Line Procol - is there a way to swap the value and timestamp around? That would be ideal. Big ask eh?

If you don’t set a json_time_key in the JSON parser, the timestamp assigned to your LP would be current time and you can set your MQTT timestamp as a field.

The Starlark processor also provides this capability. Here’s an example on how to add the current time/time of arrival as the timestamp in your LP. You would just have your timestamp as a field from your JSON.

Hopefully that helps!

1 Like

Many thanks - I was just going to update the post and I did indeed find a workable method using Starlark.

For referenced I cloned the original where I had the timestamp from MQTT as a value and the time of arrival as the original so I could leave one changed.
The other I set the timestamp from the value and dropped the value from the Line Protocol.

Took me a while, but it definitely works.

1 Like