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:

{“Time”:“2024-01-30T10:29:03”,“DS18-Fridge”:{“Id”:“3C01E0765642”,“Temperature”:19.9},“DS18-Fins”:{“Id”:“3CFFE076929E”,“Temperature”:18.4},“TempUnit”:“C”}

I am using the following Telegraf.conf:

[agent]
debug = true

Read metrics about cpu usage

[[inputs.mqtt_consumer]]
servers = [“tcp://127.0.0.1:1883”]
topics = [
“teleperiod/+/SENSOR”,
]
username = “anon”
password = “anon”
data_format = “xpath_json”

[[inputs.mqtt_consumer.topic_parsing]]
topic = “+/+/+”
tags = “/device_id/

[[inputs.mqtt_consumer.xpath]]
metric_name=“‘fridge_temp’”
metric_selection = “child::*[starts-with(name(), ‘DS’)]”
timestamp = “Time”
timestamp_format = “2006-01-02T15:04:05”
timezone = “America/Chicago”
[inputs.mqtt_consumer.xpath.tags]
device=“name(.)”
id = “Id”
unit=“/TempUnit”
[inputs.mqtt_consumer.xpath.fields]
temperature = “number(Temperature)”

[[outputs.postgresql]]
connection=“host=localhost port=5432 user=admin password=LaurenScotty1 sslmode=prefer dbname=tsdb”

[[outputs.file]]
files = [“stdout”]

Many thanks

Simon

Hello @postsi,
Welcome!
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

Hi,

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