Data is delayed by 1 hour

Hi together,

today I started using Grafana and everything went fine with the gauge. But then I wanted to implement a graph and my whole data is shifted for about 1 hour.
When I look into my MSSQL database I get to zero value on this timestamp:

image

But in Grafana it looks like this:

So it is shifted by exactly 1 hour. Does it convert my data with some time zone functions or anything like that?

Also the gauge got the right (newest) value and the graph not with the same query?!

So basically data that is 1 hour old gets used with the timestamp of current time but only in graph.

Query:

SELECT
zeitstempel AS time,
taktleistung_ist AS IST_TAKT
FROM taktleistung
WHERE maschine = ‘maschine1’ AND zeitstempel >= DATEADD(day, -7, GETDATE())
ORDER BY 1 DESC

I had to limit the data to 1 week because there are more than 1 million rows.

Thanks for answers in advance!

Best regards
Eike

Here is a pic from gauge with graph because I can only post two images in one post.

Are you in a timezone of UTC plus or minus one hour?
What timezones are the grafana server and the pc running the browser set to?
Grafana will adjust the data in the database (which is assumed to be in UTC) to the local timezone. So either the timezone of the server or browser are wrong (in fact usually the timezone of the server will not matter) or the timestamps in the database are not in UTC put the data into the db incorrectly. Or perhaps you are adjusting the timestamp in the query.

1 Like

Thanks for your answer @clanlaw

The server running Grafana has UTC +1.

Under “Configuration” > “Prereferences” > “Timezone” it says “Local Browser Time”

Under “Home/Settings” > “General” > “Time Options” > “Timezone” it also says “Local Browser Time” and “Now delay now-” says “0m”.

Any settings false here? The mssql db column uses the datetime format but I can’t look up the set timezone now, but it should be UTC +1, too.

How are you writing the data to the db? Are you using an automatic field that inserts the current time or are you generating that yourself.

1 Like

I write into the db with an OPC UA-Client that pulls the data out of an OPC UA-Server. The timestamp I use is from the OPC UA-Server. Inside the server under “System” is a variable that is called “datetime_local”.

It has the same time as the server running Grafana.

But I think it is handled as normal UTC because of the standard with the format YYYY-MM-DDTHH:MM:SS? I googeled for the “T” between DD and HH because I thought it is an indicator for a standardized time format (ISO 8601 UTC).

My thought is, that Grafana handles the UTC +1 from the OPC UA-Server as UTC and adds +1 caused by local browser time?

Yes that sounds likely. However I think if you write it to the db correctly you can tell it to interpret it as local time and let mysql convert it to utc as it writes, I am not an expert on mysql though so don’t know exactly about that. Timestamps should always be in utc in the database otherwise when grafana asks for data around the DST change it will either get two samples for the same time or there will be a gap in the data. With the data in the db in UTC then grafana will convert it local time and should not be confused by the DST change.

1 Like

If you are fetching current data from the the OPC server and immediately writing it to the db then you would probably better to use an automatic timestamp field in the db and let mysql insert it. That is ok provided you don’t mind it being a short time off due to the time taken to fetch it. It obviously won’t work if the server buffers up data over a time then sends it to you later.

1 Like

I use MSSQL but I think it handles it the same way MySQL does. I can’t check it until tomorrow. But thanks for the ideas @clanlaw ! I’ll update the issue tomorrow.

Thanks!

In future I probably use a time-series db for that case. But you are right… I might overthink that. New to the field :confused: In the past I just queried the database and never created tables and so on.

If you have a choice for time series data then a good choice is Influxdb.
I misread your initial post and thought you were using MySQL. I imagine MSSQL is similar.

1 Like

I tested it with using the normal “dateime” variable from the OPC UA-Server and not the “datetime_local”. It actually worked for me. So the “datetimelocal” variable is UTC +1 but Grafana interpreted it as UTC and added +1 hour, so the timestamp was correct but with 1 hour old data.

Solved. Thanks to @clanlaw for giving me the right idea.

Hi.

I have the same issue. Timestamps are correct. If I press the switch at 15:30 it will write to database as 15:30.

So it stores Local timestamp instead of UTC. And I read that is wrong.

But grafana time picker seem to find it it one hour ahead and will not show it using Last X…presets.

Im guessing the 1h difference happens inside grafana because UTC and Local time difference, which is exacty 1h in my case.

I would like to find the solution that doesn’t brake at daylight time savings.

What have you actualy done to fix the issue?

Thank you
Br,
Kd