Wrong Date from datetime of metric value

  • What Grafana version and what operating system are you using?

Grafana v9.5.21 (2dd6ebef03fbe42927769bf00bcf0bc4e621bb9c)

  • What are you trying to achieve?

get timestamp of the last metric value and show it on dashboard panel.

  • How are you trying to achieve it?

Im using VictoriaMetrics DataSource.

in bash terminal I can request my datasource and can see that the LAST timestamp of metric is - 1735968707000:

#curl -G 'http://localhost:8428/api/v1/export' -d 'match[]={srv_ID="2"}'
..................
{"metric":{"__name__":"T0_0cm","srv_ID":"2"},"values":[-0.44,-0.5,-0.69,-0.69,-0.69,-0.63,-0.5,-0.5,-1.06,-0.56,-0.63,-0.69,-0.94,-0.37,-0.25,-0.25,-0.19,-0.12,-0.19,-0.19,-0.19,-0.19,-0.31,-0.25,-0.25,-0.25,-0.25,-0.25,-0.25,-0.25,-0.31,-0.31,-0.44,-0.37,-0.31,-0.31,-0.31,-0.31,-0.31,-0.31,-0.25,-0.25,-0.31,-0.44,-0.56,-0.5,-0.37,-0.5,-0.56,-0.56,-0.44,-0.37,-0.37,-0.31,-0.31,-0.31,-0.31,-0.31,-0.31,-0.37,-0.37,-0.37,-0.44],"timestamps":[1730362785000,1730363884000,1730884290000,1730884422000,1730896046000,1730955601000,1731042002000,1731128401000,1731214801000,1731301201000,1731387601000,1731474001000,1731560402000,1731646801000,1731733202000,1731819601000,1731906001000,1731993484000,1732078801000,1732165201000,1732251601000,1732338001000,1732425172000,1732510801000,1732597201000,1732684455000,1732770092000,1732856401000,1732942801000,1733029292000,1733115601000,1733202090000,1733288405000,1733375663000,1733462771000,1733547601000,1733634002000,1733720401000,1733806801000,1733894206000,1733981075000,1734066093000,1734152401000,1734238892000,1734326650000,1734412850000,1734584401000,1734670800000,1734757201000,1734845233000,1734931386000,1735017335000,1735103979000,1735190190000,1735276565000,1735363282000,1735449310000,1735535569000,1735621200000,1735709608000,1735794092000,1735880491000,1735968707000]}
...........................

from https://www.epochconverter.com/ it means that timestamp is - GMT : Saturday, January 4, 2025 5:31:47 AM

this is correct timestamp for my metric value.
I want to show it on my dashboard.
this metric “T0_0cm” updates one time per day in the same time at morning.

to get timestamp of the last value of this metric I use this query:

(tlast_over_time(changes(T0_0cm{srv_ID="2"}[24h])))*1000

  • What happened?

with this settings it show me correct time but the date is wrong - it always on 1 day after the correct date.

  • What did you expect to happen?

it should be Jan 4, but in fact it shows as Jan 5.

Im not sure - where Im wrong? Can anyone point me how to get the correct datetime?

Hi,

I might be mistaken but using changes function would “shift” your result the time window in the future (I won’t show an example unfortunately but you can play with your metric - on time series graph display T0_0cm{srv_ID="2"} and changes(T0_0cm{srv_ID="2"}[24h]) and you’ll probably notice what I’m talking about), so the query returns the correct value. You can omit the [24h] window or just give up the changes function entirely.

Or maybe not

Another thing I noticed is when you’re using tlast_over_time you get the timestamp of the metric, so you don’t really want to display the time field - you want to display numeric fields with unit of Time. I think it doesn’t matter in your case, since you’re taking tlast_over_time with default lookbehind window (1m in your case), which would give you +/- one minute and I think that’s acceptable, but what I would do would be to write the query as

(tlast_over_time(T0_0cm{srv_ID="2"})[<T1*>])*1000

which would give you a timestamp and then display Numeric fields, then go to Standard Options -> Unit and search one that would suit you (something with time but that was always my Achilles heel).

  • The <T1*> I used in the query is the time you’re willing to search the metric in the past. Anything more than that (and Grafana’s time picker) won’t be displayed, so if your metric expired e.g. 10 days ago and you set Grafana’s time picker to Last 3 hours and the <T1*> value to 1d you won’t see the timestamp.
1 Like