Feature Request - Time template variable type

(I reckon this has probably already been requested, at least in other forms)

Feature Request - a new type of Template Variable:

    • Either a Date/Time specification;
    • Or a Date/Time Period specification.

If we have #1, the simplest, I can add 2 DateTime selectors to the templates row, say “$beginning1” and “$end1”, and then I should be able to make a graphic or whatever that uses those 2 time filters.

Then, I can build, for example:
# Row 1 - CPU chart, WHERE time >= $beginning1 and time <= $end1
# Row 2 - CPU chart, WHERE time >= $beginning2 and time <= $end2

Thus being able to compare time periods. Example, compare today vs yesterday, a very important requirement for analysis of trending over time or of comparison of specific periods (ex: this Black Friday, vs last Black Friday).


Of course, current Grafana’s structure won’t cope with that, since the graphics’ X-Axis are per Dashboard’s time specification instead of per time specification of its own.

Is this different from the current time shift function? Some data sources (like Graphite for example) support time shifting at the query level as well.

Is this feature request asking for something extra that does not exist today?

@daniellee
Thanks for that, somehow I never became aware of that feature. It’s a very useful tool for monitoring trends over time, like compare Today vs Yesterday.

I had made some experiments with time filters (hard-coded in the query) and it appeared to me that different time periods per graphic were not possible - I was seeing one graphic showing 1H worth of data for today and another showing 1H worth of yesterday as expected, but both graphics encompassing from yesterday until today…


@daniellee
However, it’s still not the same thing. That (very useful) feature doesn’t allow to compare periods that are not hard-coded in the dashboard.

Example: I want to compare this year’s Easter promotion to last year’s Easter promotion. Or I want to compare the results of a performance test a few hours ago against a performance test some random time a couple of days back.

If we had Template Variables that allowed us to specify times we would be able to leave it … “variable”. If those variables also allowed to be “relative” to the main time-filter, we can have those variables hidden and thus also cover the functionality you just mentioned with one integrated one.


Ex, imagine the dashboard showing us as filters (akin to the “time shift function”):

  • $server = SHOW TAG VALUES FROM “cpu” WITH KEY “host”
  • $alternateSince = $mainFilterSince$ - 24h {hidden}
  • $alternateTo = $mainFilterTo$ - 24h {hidden}

Or, user chosen (akin to “Ad hoc filters”):

  • $server = SHOW TAG VALUES FROM “cpu” WITH KEY “host”
  • $alternateSince {user-chosen}
  • $alternateTo {user-chosen}

Then panels querying with:

SELECT “cpu_idle” from “cpu” WHERE “host” = $server AND time >= $alternateSince AND time <= $alternateTo

1 Like

Is it the same as this feature request?

@daniellee
I read (red) the thread but can’t quite figure out for sure.

The original poster appears to be asking for the exact same thing but with a different objective (for generating links!?).

Then the discussion appears to delve into the ability to generate links, potentially (I couldn’t quite figure out) aiming at an implementation that would or would not suit this need. A proposed solution by user “mtanda” isn’t very clear and there doesn’t appear to exist a single concrete clear proposal.

So, in sum, not sure - nothing about that feature request appears clear… Sorry but I haven’t got a better answer…

Please open a new Feature Request then with your use case. My use case for fixing this would have been from the plugin angle which is a little bit different from yours. Hopefully someone will pick it up and send a PR (happens quite often but no guarantees).

My company isn’t paying for anything yet. Even though Grafana is a commercial institution, I really appreciate everything we’re already getting from Grafana and no one is in obligation of giving us even more than the awesomeness we’re already getting.

Thanks.

1 Like

Hi @pauloasos

Were you able to figure out how to do this? I am having the same requirement. My datasource is redshift. And I am using grafana 4.6.0 beta version.

Thanks,

This is now possible for mysql and postgres in the latest master and will be released in the next version of Grafana in January:

Both the sql dbs have macros for time from and time to. For example, you could have the following in your template variable query if you have “On Time Range Change” selected:

select $__timeFrom()

Hi is it also possible to use $__timeFrom() on MSSQL query?

Regards

Luis Oliveira