How to configure quick ranges for time picker?

  • What Grafana version and what operating system are you using?
    9.3.6 Grafana cloud trial

  • What are you trying to achieve?
    I am trying to set time range in time picker to be matter of days. For the data source I want to use Grafana for, I want to only show “Last 2 days” and before than (i.e. Last 1 month, etc.)
    Essentially, I want to hide all time ranges until last 24 hours (include last 5 mins, etc) as they are distraction to our enterprise users.

image

  • How are you trying to achieve it?
    Don’t know how. I only see refresh internal configuration, not for “quick ranges for time picker”

  • What happened?
    I am unable to set time range in time picker to be matter of days. For the data source I want to use Grafana for, I want to only show “Last 2 days” and before than (i.e. Last 1 month, etc.)

  • What did you expect to happen?

  • 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.

  • Did you follow any online instructions? If so, what is the URL?

2 Likes

@RajEnterprise

AFAIK, one cannot modify the list of values in the time picker. However, you can “fix” the relative time on each panel to ignore the time picker. See below where the relative time has been set to 2d (and thus ignores the “Last 1 hour” in the drop down).

1 Like

Hi @RajEnterprise

I have moved this post to the Grafana Cloud category.

Regarding your question. That setting is actually hard-coded. Maybe someone from the Grafana Cloud team can answer if there is a way to do customized the time-picker box in the non-OSS version.

Is it able to be modified in Grafana OSS?

I don’t think it is possible

any plugins available

1 Like

would like to see this Functionality added also (in my case to the non cloud version).
Just like how you can specify on a per dashboard level custom auto refresh time-frames, users should be able to add custom Time Picker entries (ie i would like to add “Last 3 days” , “last 5 days” ) since the jump from the default Last 2days to Last 7 days , is frequently too large a gap for quick looks.

thanks

1 Like

they can use this.

Notice when you do now-5d it updates top right to Last 5 days

image

im looking for this ability / functionality also (in non-cloud grafana).
Of course you can manually type in an absolute time range, but what I’m looking for (and I assume the others in this post) is the ability to define the quick ranges (ie on the right side) so that they apply on all dashboards and can be easily and quickly selected.

thanks

We would also like to edit the quick ranges for the time picker. Failing that, “Last 3 days” would be a very welcome addition to the hard-coded list.

@dlcdevdashboard Welcome to the Grafana forum.

I think you already know this, but you can override the Time Picker and set different time ranges for any data source by using “Query options” → “Relative time”.

and you can hide the Time Picker in Dashboard settings (cog icon) -> General

And you can use the plugin from @mikhailvolkov to make your own Datepicker.

1 Like

I’ve just posted a -new- topic with a workaround that might be solution for you

Being able to configure the quick ranges per dashboard would be a great feature.

2 Likes

post it as a feature request on grafana github

The suggested custom timepicker plugin doesn’t do what I want.


FWIW, for self-hosted Grafana here’s a :warning: dirty hack that noone should do :warning: (because it’ll get overwritten by grafana updates!) — that has anyway helped me to remove the Last 12 hours option. IMO it is useless, just takes space obscuring the Last 7 days option which I use far more often.

Step 1. Locate your grafana server directory. In my case (apt repo .deb install) it is /usr/share/grafana. Its contents should be like this:

admin@i-038e9a3f34a5ebf9f:~$ ls -F -w80 /usr/share/grafana
Dockerfile  README.md  conf/  npm-artifacts/    public/
LICENSE     VERSION    data/  packaging/        tools/
NOTICE.md   bin/       docs/  plugins-bundled/
admin@i-038e9a3f34a5ebf9f:~$ 
admin@i-038e9a3f34a5ebf9f:~$ cd /usr/share/grafana
admin@i-038e9a3f34a5ebf9f:/usr/share/grafana$ 

Step 2. Find the JS files under public/build which hardcode the quickranges / timepicker options:

$ grep -Rnwl 'Last 24 hours' public/build
public/build/7462.d83af2435fe93a4c1754.js
public/build/3719.c065b2e146c4c8347d51.js
public/build/3719.c065b2e146c4c8347d51.js.map
public/build/7462.d83af2435fe93a4c1754.js.map

Depending on build version, the exact filenames will differ. These are known as “webpack chunks”; doesn’t matter for our purpose.

Step 3. Edit the files. :skull_and_crossbones: Make backup first, if unsure what you’re doing.

$ sudo sed -i 's/{from:"now-12h",to:"now",display:"Last 12 hours"},//' \
  public/build/{3719,7462}.*.js

These are minified javascript files, with very long lines, a bit of a PITA to edit with conventional file editors. So I’ve used trusty sed.

Ignore the .js.map files; they’re only there for debugging grafana frontend, not essential for normal UI functionality. Restore from backup (or reinstall from deb package) if correct sourcemaps are somehow needed afterwards.

Step 4. Validate what you did. No need to restart grafana server; but you do need a cold-refresh in the browser, to bust caches. CtrlShiftR, CtrlShiftF5, CmdShiftR, CmdShiftF5, shift-click the browser refresh button… whichever way you do it.


TL;DR: just edit the JS files. Not perfect, but works.