Telegraf xpath timezone failing

I am trying to set the timezone for an mqtt source which I am parsing with xpath (see below). However, the time written to the underlying postgressl DB (timescale enabled) is always UTC. I have tried using Localhost as well as specific timezones. Am I doing something wrong?

I have the following mqtt message:


I am using the following Telegraf.conf:

debug = true

Read metrics about cpu usage

servers = [“tcp://”]
topics = [
username = “anon”
password = “anon”
data_format = “xpath_json”

topic = “+/+/+”
tags = “/device_id/

metric_selection = “child::*[starts-with(name(), ‘DS’)]”
timestamp = “Time”
timestamp_format = “2006-01-02T15:04:05”
timezone = “America/Chicago”
id = “Id”
temperature = “number(Temperature)”

connection=“host=localhost port=5432 user=admin password=LaurenScotty1 sslmode=prefer dbname=tsdb”

files = [“stdout”]

Many thanks


Hello @postsi,
Hmm it should work it is a relatively new addition though:

I would encourage you to create an issue in telegraf instead.
Thank you
Unless @jpowers has been seeing this


The timezone config option tells telegraf what timezone the timestamps your data has is in. So you are saying my data is in “America/Chicago” and do not to assume it is UTC.

Timestamps read by telegraf are internally stored as unix timestamps. Unix timestamps do not have timezones. So they are all stored to UTC, relative to the timezone you specified. It is more common to see users want to store their timestamps in UTC, and use whatever reporting mechanism to change the timestamp (e.g. grafana).

That said, the postgres output does has an option to specify a field for the timestamp of your data and an option to specify whether it includes a timestamp or not. If you wish to keep the timezone info with your data, then do not not parse the timestamp, and instead store it as a field and use these other mechanisms.

I’m not sure my understanding above is correct. We added an option to specify if the timezone includes a timezone and that is about it. Consider trying that in the postgresql output first.

Hope that helps.

edit: modified my response about the postgresql output