Delta for a static 24h window

Does anyone know how to create a graph that would track changes for the current day (i.e. current 24 hours)? The closes thing I found is using delta with a 24h time range, such as:

delta(my_metric_total{kubernetes_namespace=“my_namespace”}[24h])

However, this results in a sliding window, which starts to subtract gradually from the sum as its lower bound transitions over value increases 24 ago. Ideally I would like this sliding window to be static for midnight to now, so that there is a reset to 0 at the end of each day. Maybe this is not possible at all, but any ideas would be greatly appreciated.

Do you mean you want to show the difference between the value and that at the start of the day? If so the below query shows the difference between value and that at the start of the chart, which is the same thing if you set Today as the range. Alternatively you could adjust the query accordingly. I am not an SQL expert so there may well be more efficient ways of doing this. The query works for MySQL so again might need adjusting. I use it for showing the rainfall during the graph period.

SELECT
  $__timeGroupAlias(measured_at,$__interval),
  max(rain_total_mm)-@start AS "rain"
FROM samples AS tbl
CROSS JOIN (select @start := `rain_total_mm` from samples where measured_at>=$__timeFrom() limit 1) AS sub
WHERE
  $__timeFilter(measured_at)
GROUP BY 1
ORDER BY $__timeGroup(measured_at,$__interval)

Now I look at it again I think I might be missing an ORDER BY in the inner query.
Looking at it again, again, I think the inner query should pick up the last one before or equal to the start, not the first one at or after it.

Yes, that’s exactly what I’m trying to do. But unfortunately a MySQL query won’t work in my case (sorry I should have explained my setup better). I have a prometheus data service, collecting the metric of a simple counter in another application, so the query I wrote above is for grafana to prometheus. This counter is incremented every time the application sends a particular message and can have thousands (sometimes tens of thousands) of increments over the course of the day, with a repeating pattern day to day. So summing up the values tends to create an ever growing line with diminishing details while a sliding window creates odd looking drops…

I don’t understand what you mean by " a graph that would track changes for the current day" in that case. Perhaps a diagram would help.