Skip to main content

9.3 Image Rendering

Usually, regular notifications through Grafana can be quite hard to read and understand. However, instead of receiving text-based Grafana Notifications through your alert channels, you can enable Grafana to render a picture of the metric, just as it is shown when logging in to the Grafana dashboard directly.

info

The following steps are performed on your 📟 node server.

Install Image Renderer

To add the Image Rendering tool to your Grafana server, you have to install it's package.

1.1 Check Grafana Version: Verify which Grafana Version you have installed before breaking support.

grafana-server -v

1.2 Install Render Plugin: Use the built-in Grafana-CLI to install the suited image renderer for your Grafana installation.

sudo grafana-cli plugins install grafana-image-renderer 3.10.1

1.3 Enable Image Capturing: Add image captures to the global Grafana cofiguration file using your preferred text editor.

sudo vim /etc/grafana/grafana.ini

Then search for the following text section:

#################################### Unified Alerting ####################

[unified_alerting]

1.4 Set Image Capturing: Underneath the Unified Alerting section, add the screenshot settings and safe the file.

[unified_alerting.screenshots]
capture = true

The final section will look like this:

#################################### Unified Alerting ####################

[unified_alerting.screenshots]
capture = true

[unified_alerting]

1.5 Install Dependencies: Install all necessary packages for the image rendering software.

sudo apt install -y libx11-6 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrender1 libxtst6 libglib2.0-0 libnss3 libcups2  libdbus-1-3 libxss1 libxrandr2 libgtk-3-0 libasound2 libxcb-dri3-0 libgbm1 libxshmfence1

1.6 Grant Permissions: Grant the Grafana service user all necessary rights to read and execute plugins.

sudo chown -R grafana-server-worker:grafana-server-worker /var/lib/grafana/plugins

1.7 Refresh Grafana: Restart your Grafana server for the dependency to show up.

sudo systemctl restart grafana-server

1.8 Verify Grafana Status: Check if the Grafana Server restarted correctly.

systemctl status grafana-server

The output should look similar to this:

● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled; vendo>
Active: active (running) since [DATE]; [TIME] ago
Docs: http://docs.grafana.org
Main PID: 28472 (grafana)
Tasks: 30 (limit: 38043)
Memory: 150.4M
CPU: 6min 59.027s
CGroup: /system.slice/grafana-server.service
├─28472 /usr/share/grafana/bin/grafana server --config=/etc/grafan>
└─28490 /var/lib/grafana/plugins/grafana-image-renderer/plugin_sta>

[DATE] [TIME] [USER] grafana-server[28472]: logger=context userId=1 orgI>...
...
tip

From now on, all notifications will automatically send graphs once the alert is triggered.

Revert Setup

If something went wrong, you can disable image rendering or remove the plugin all together.

1. Disable Image Capturing: Open the Grafana configuration file and remove or comment out the screenshot settings.

vim /etc/grafana/grafana.ini

Locate and remove or comment out the following section:

[unified_alerting.screenshots]
capture = true

2. Remove the Render Plugin: Uninstall the image renderer plugin using the Grafana CLI.

sudo grafana-cli plugins uninstall grafana-image-renderer

3. Clean Up Plugin Directory: Manually ensure all images and cache are removed from the plugin directory.

sudo rm -rf /var/lib/grafana/plugins/grafana-image-renderer

4. Revert File Permissions: Reset ownership of the plugin folder if it was changed previously.

sudo chown -R root:root /var/lib/grafana/plugins

5. Restart Grafana: Restart Grafana to apply the changes.

sudo systemctl restart grafana-server

6. Verify Grafana Status: Ensure Grafana is running properly after reverting the changes.

systemctl status grafana-server

The output should look similar to this:

● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled; vendo>
Active: active (running) since [DATE]; [TIME] ago
Docs: http://docs.grafana.org
Main PID: 28472 (grafana)
Tasks: 30 (limit: 38043)
Memory: 150.4M
CPU: 6min 59.027s
CGroup: /system.slice/grafana-server.service
├─28472 /usr/share/grafana/bin/grafana server --config=/etc/grafan>
└─28490 /var/lib/grafana/plugins/grafana-image-renderer/plugin_sta>

[DATE] [TIME] [USER] grafana-server[28472]: logger=context userId=1 orgI>...
...
tip

Grafana will now stop rendering images in alert notifications and revert back to text-based alerts.