How to automatically update default variable value?

Hi,

I’m building a dashboard to visualize the status of our system during a certain day (actually, night…). The metrics are coming from Prometheus, and are labeled with night that takes the form of YYYYMMDD. I have a variable named night which queries Prometheus for available night label values, and lets the user choose which night to display (screenshot attached below).

Where I’m stuck is how to automatically update the default value of night to the most recent one. I’d like the dashboard to switch over to the most recent night (otherwise it’s very easy for a viewer to forget to do that manually and they end up looking at stale data). E.g., in the attached screenshot, 20180604 is selected (and the dashboard was saved). In the meantime, 20180605 has appeared in the database, but that didn’t cause the selected value to change when the dashboard auto-refreshed.

My question – is there a way to achieve this (hopefully w/o having to resort to a scripted dashboard – it’s nice to be able to perform WYSIWYG edits)?

Any help or pointers would be much appreciated!

2 Likes

Hey,

Very late answer but if anyone is looking for this I’ve find a way:

You need to set your default value to nothing and it will automaticly select the first value.

  • For that you first need to select a value, notice that it added a parameter in the URL of your browser like YourDashboard.domain?orgId=1…&var-YourVar=81255

  • Remove the value after the = like YourDashboard.domain?orgId=1…&var-YourVar= then press enter, it will show you a broken dashboard with no value, press SaveDashboard and check the box “Save current variable values as dashboard default”.

  • Now when you acces your dashboard trough a normal link (no &var-YourVar=… in url) it will automaticly select the latest value (provided that you set your variable values to be refreshed at dashboard refreshed and ordered properly)

1 Like