Year over year data from datasource

  • What Grafana version and what operating system are you using?
    v9.4.7 on k8s

  • What are you trying to achieve?
    I’m trying to make a dashboard that shows current data vs the previous years data. The data is from a JSON API datasource.

  • How are you trying to achieve it?
    I’m trying to monkey with the query parameter on the request. Currently I have:

  • What happened?
    I don’t know how to or if I can do calculations on the above.

  • What did you expect to happen?
    That when I googled I would find examples of how to do calculations on the above.

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    I can see errors from the RRDReST app when I naively try to change the dates around

  • Did you follow any online instructions? If so, what is the URL?
    Can’t find any :frowning:

welcome @boringeye

you are on the right track. but does rrdrest expect epoch milliseconds or seconds?

It wants seconds, the expression I gave works to get data for the time period selected on the dashboard.

I was thinking maybe I could do something like ${__from:date:seconds}-31536000 to have another line on the graph shifted a year back, but I’m not finding how to make that work.

Of course, there may be another better way I’m not thinking of because I am quite new to grafana.

So when you say year to year you mean last year 06/06/2022 to 06/06/2023 type of thing?

what visualization are you plotting this on?

If I’m looking at the dashboard and I’ve got the past week (May 30-June 6, 2023) selected in the time selector I want to have two lines, one with the data for the past week and one with the data for a week roughly a year ago (~May 30-June 6, 2022).

Whether that’s 365 days ago or the same dates in a previous year I don’t think it matters.

I’ve done this in the past with graphite by using the timeShift function.

maybe the following 2 possible options:

  1. two separate queries to rrd, one using one year back and one using current
  2. using apache echart grafana plugin wherein you have more control over the dates


I’m trying to do option 1, but I can’t figure out the keywords to find the documentation on how to do the date calculations.

could you please provide sample rrd files that we could use to test this out. I got rrd running locally but the rrd files in tests folder seem not to have the dates from last year unless you can show us how to generate rrd files with needed data, maybe via python or something?

I can’t figure out how to upload one, but I think this will make one:

$ rrdtool create random.rrd --start now-3y --step 3600 DS:random:GAUGE:7200:U:U RRA:AVERAGE:0.5:1:17520 RRA:MIN:0.5:12:87600 RRA:MAX:0.5:12:87600 RRA:LAST:0.5:1:17520
$ for i in $(seq $(date -d "2 years ago" +%s) 60 $(date +%s)); do rrdtool update random.rrd --template random $i:$(($RANDOM%100));done

I think it will take a long time though

1 Like

Maybe time to go for lunch :joy:, this stuff is still chugging away. What would be the first data point to be populated with the randomizer? and are you looking for a time series for this?

Can you please post a simpler data generator? just 12 months one day per month for this year and last year?