We are going to see how we can convert our Grafana dashboards into images, so we can share them anywhere, for example in slack, discord, microsoft teams, etc. With this we will be able to preview our dashboards without the need to enter Grafana and create automations to send them to our teams.
Prerequisites
Note: We need a running instance of Grafana, version 8.3.11 or higher. Grafana >=8.3.11
We need to have the plugin Grafana Image Renderer installed in our Grafana, to be able to render our dashboards in images, and to generate the necessary endpoints to be able to make the requests.
The first option is to install this plugin from its CLI, using the following command:
Another option is to install it via docker, for that we need to add the following image to our docker-compose:
To start the services, run:
Note: Make sure you have your API Key from Grafana, in order to be able to make API requests.
Usage
Step 1: Get the UID of the dashboard
The first thing we need is the UID of the dashboard we want to render, for this we are going to use the Grafana API.
With this we will get a list of all the dashboards we have in our Grafana, and we will be able to see the UID of each one, so we are only interested in the uid
and title
node to know which dashboard we want to render.
Step 2: Get the dashboard detail
Next we need to get the detail of this dashboard, for that we use the following command:
From here we will obtain the JSON with all the information of our dashboard, and its panels in the node dashboard.panels
, we are interested in the id
of each panel to be able to render it and the title
to identify it.
Step 3: Render the panel
As a last step, we need to make the request to the endpoint of our Grafana Image Renderer, for that we use the following command:
Make sure you change the values of these mandatory variables:
API_KEY
: with your Grafana API Key.GRAFANA_URL
: with the URL of your Grafana.DASHBOARD_UID
: with the UID of the dashboard you want to render (we got it in the first step).INIT_TIMESTAMP
: with the start timestamp of the image. (Example: 1724011204)END_TIMESTAMP
: with the end timestamp of the image. (Example: 1724011204)PANEL_ID
: with the ID of the panel you want to render. (We got it in the second step)ORG_ID
: with the ID of your organisation.
Note: You can change the
width
andheight
to change the size of the image. You can also change thetz
to change the timezone and thescale
to change the image quality.
This will generate an imagen_dashboard.png
file with your dashboard image.
Extras
I have left an example of a library I made in Typescript
to make this easier,
This library provides you with 3 methods to render your dashboards, which are the 3 steps we saw before.
Take it as a guide to make your own automations.
You can see the code in this repository