Grafana dashboard: automatically set a date variable to the current date

I have a Grafana dashboard with a date variable. I always update the possible values once a day via a job to always be [currentDate - 2, currentDate - 1, currentDate, currentDate + 1, currentDate + 2] (I update the data source through the job). Sometimes the values can also differ, but the current date is always in there.

Now my users complained that the default value of that variable is always the first one, which is not always the current date. They want the default value to always be the current date (based on a predefined timezone).

I know that I can update this manually every day. Go into the dashboard, update the date and save. I do not want to do this. I want to update this automatically.

What way is there to do this? Does Grafana offer some native functionality with which to do it? Or do I have to do this with an external job or through some other means?

Upvotes: 0

Views: 5877

Answers (1)

Jan Garaj
Jan Garaj

Reputation: 28716

Make currentDate first in that variable list (yes, users may complain that it isn't in the logical order, but you can't have everything - unless you don't want to code own Grafana) and never Save current variables -> Grafana will preselect first value from the variable list in this case.

If you already have some saved current variables, then you need to edit dashboard model manually (export dashboard json/edit json - variable definition/import dashboard json).

Upvotes: 0

Related Questions