Javascript/jQuery event on regular refresh intervals?

I have a custom javascript panel which loads and prints an RSS feed.
I’d like to have it refresh at regular intervals.
Currently I’m using a simple setInterval to refresh every few minutes.

I’d prefer to synchronize to the refresh rate of the dashboard instead.
It seems to me there is probably some sort of global event triggered on every refresh that my script should be able to listen to using jQuery.
Is there such an event my script can listen to?

Yes, you can bind to the refresh event like this:

Thanks! I guess that only works for proper plug-ins, and not for small Javascript bits in the Text/HTML panel? Ah well, might be wise to just go ahead with a full plug-in anyway.

Oh, didn’t understand that was what you meant in your original question. Haven’t tried it but something like this might work:

Yes! That’s perfect!
I ended up with something roughly like this:

function doSomething() {
  // ...
};

doSomething();
angular.element('grafana-app').injector().get('timeSrv').$rootScope.$on('refresh', doSomething);
2 Likes

angular.element('grafana-app').injector().get('timeSrv').$rootScope
is undefined on Grafana 6.2.5
Instead, this now works:
angular.element('grafana-app').injector().get('$rootScope').$on('refresh', doSomething);

Hi! How can you do this in react?

The current time range is injected into the panel. So when that changes, it should cause a re-render.

1 Like

working solution for Grafana 7+

function doSomething() {
  console.log("refreshed")
};
angular.element('grafana-app').injector().get('timeSrv').dashboard.events.emitter.addListener('refresh', doSomething)