Current value in legend for terminated time series

I’m using Grafana to visualize several time series and I have set the legend to table showing the current and total values. A problem seems to be that my time series are not continuous in a way that a time-series can terminate at any time while new series can appear at any time.

This probably causes the undesirable behaviour that always the last known value of a series is treated as the current value of the series. I actually want Grafana to understand that a series has ended when no new observations arrive. While it is senseless wanting to remove such legend entries altogether, at least I want Grafana to set a current value of 0 when no further observations arrive.

Probably this is not possible in Grafana itself, but maybe I can handle this behaviour by a modified data query. I’m using MySQL as data source. Does anybody has advice how I could achieve this desired behaviour?

This is exactly why specialized timeseries databases exist - they have functions for this sort of thing. (like the FILL function for InfluxDB). We can hopefully build this into the MySQL data source over time but the database itself has no support for most timeseries functions.

To do this with sql:

  1. you will need to do a group by time - for example group by hour. This will make the data regular - once every hour for example (rather than irregular like it seems it is in your case).
  2. then your query will need to fill in zeroes for the empty intervals - something like the solutions suggested here:
    https://stackoverflow.com/questions/2479773/mysql-filling-empty-fields-with-zeroes-when-using-group-by

I’m not sure how to do part 2 in this case. Maybe someone has already written something similar they could share?