Suggestions to display the date or time since a particular date

I want to monitor and highlight when data in tables has not been updated for a while. The tables all have CreateDate fields so I use the last CreateDate to determine if the table has not been written to for X hours by using a max(CreateDate) in the SQL

What would be the best way to represent this on a Grafana Panel? It would be great to see it going amber when it’s close to too old and then red when it is out of date.

1 Like

I’m looking for the same thing since two days now

1 Like

How about use a Stat panel to display the last Create date? Not sure if you will be able to set up thresholds (color of Stat panel to change) based on X hours or such, but you can try.

More info to get you started here: How to show time of min (or max) value? - #4 by viapass

I found a solution for me:
I displayed the date in a table graph and then hid the panel like this

Screenshot from 2021-03-10 09-57-51

Screenshot from 2021-03-10 09-58-07

then i added text panel and with some javascript code i got the date and displayed the difference

Screenshot from 2021-03-10 10-01-36

1 Like

Can you share the javascript code that you used in the Text panel to get the date & display the difference?

setTimeout(() => {
var x = document.getElementsByClassName(“css-1hlp2kn”);
var date = 0
for (i = 0; i < x.length; i++) {
if (x[i].innerHTML.startsWith(“20”)) {
if (Date.parse(x[i].innerHTML) > date) {
date = Date.parse(x[i].innerHTML)
}
}
}
var now = new Date();
var diff = now - date;
var msec = diff;
var hh = Math.floor(msec / 1000 / 60 / 60);
msec -= hh * 1000 * 60 * 60;
var mm = Math.floor(msec / 1000 / 60);
msec -= mm * 1000 * 60;
var ss = Math.floor(msec / 1000);
msec -= ss * 1000;
if (hh > 0) {
hh = (“0” + hh).slice(-2)
res = hh + “:” + mm + “:” + ss
} else {
mm = (“0” + mm).slice(-2)
ss = (“0” + ss).slice(-2)
res = mm + “:” + ss
}
$(’#lastUpdate’).text(res);
}, 4000);

2 Likes

This topic was automatically closed after 365 days. New replies are no longer allowed.