Skip to main content

Grafana Events (EventBus)

Grafana leverages an EventBus to broadcast application events, enabling different parts of the system to respond when a user interacts with the interface. This mechanism facilitates real-time communication across components.

Here’s a simple example of subscribing to an event:

const subscription = eventBus.subscribe({ type: "data-hover" }, () => {
console.log("Data hovered");
});

return () => {
subscription.unsubscribe();
};

Predefined Events

The EventBus supports a variety of predefined events. Below is a list of key events and their purposes:

EventDescription
absolute-timeTriggered when a user selects an absolute time range on the dashboard
annotation-eventFired when an annotation is created, updated, or deleted
annotation-query-finishedOccurs after an annotation query completes
annotation-query-startedOccurs when an annotation query begins
copy-panelInitiated to copy a panel’s JSON to local storage
dashboard-loadedFired when a dashboard finishes loading
dashboard-savedTriggered after a dashboard is saved
data-hoverOccurs when hovering over a legend or data point with shared crosshair enabled
data-hover-clearFired when the user stops hovering over a data point with shared crosshair enabled
data-selectTriggered when a user selects a data point on a panel
datasource-updated-successfullyFired when a datasource update succeeds
panel-edit-finishedOccurs when a user finishes editing a panel
panel-edit-startedTriggered when a user begins editing a panel
refreshFired when a dashboard is refreshed
renderOccurs when a dashboard is rendered
shift-timeTriggered when the dashboard’s time range shifts
theme-changedFired when the theme settings are modified
time-range-updatedOccurs when the time range is updated
variables-changedTriggered when dashboard variable values change
variables-changed-in-urlFired when variable values in the URL are updated
variables-time-range-process-doneOccurs when the time range processing for variables completes
zoom-outTriggered when the user zooms out the time range

Panel Interconnectivity via EventBus

You can harness the EventBus to enable communication between panels in Grafana. For a practical example, the article below explores how to use Business Charts, Grafana Events, and Extended Result to send and receive events, enhancing panel interactivity.

Panels interconnectivity in Grafana via EventBus
Panels interconnectivity in Grafana via EventBus

Conclusion

The Grafana EventBus is a powerful tool for developers looking to create dynamic, responsive plugins. By subscribing to predefined events—or even defining your own—you can build interconnected dashboards that react instantly to user actions.

Whether you’re enhancing visualizations or enabling cross-panel communication, mastering the EventBus unlocks a new level of flexibility and control in Grafana development. Dive in, experiment, and see how far you can push the boundaries!