We created panel plugin template for Grafana
Grafana has excellent tutorials on building panel plugins, but we found ourselves repeating the same steps when creating custom plugins for our customers. Eventually, we decided to create our template for a panel plugin, which I hope can be helpful for the community.
Grafana's tutorial Build a panel plugin provides information on setting up the environment, creating a new plugin, and explaining the basics of a panel development using data frames and options control. It's a great starting point, and we recommend reading it before continuing with this article.
As I mentioned before, we wanted to have a template, which can be used as a base for a new panel with everything in place and updated to the latest version of Grafana. We called it the Abc panel template.
Since publishing this blog Abc panel template was archived. We recommend to use Plugin Tools to create new plugins.
Panel plugins
Panels allow visualizing of data received from data sources. While Grafana has several built-in panels like Table, Time Series, and Text, you can also create your custom panels.
![Panel plugins are registered in the Grafana Catalog and provide many visualization options and features.](/img/blog/2021-12-10-panel-template/panels.png)
There are a lot of use cases that require custom visualization with additional logic implemented on the front end, which goes beyond standard and available panels.
Docker container
For all of our developments, we use Docker and Docker Compose to orchestrate containers. Compose is a tool for defining and running multi-container Docker applications.
Here are some benefits of using Docker containers compared to locally installed Grafana.
- Easy to deploy and share configuration with team members and customers.
- Allows testing plugins against multiple versions and the main branch to be prepared for the upcoming release.
- Docker always starts from a fresh configuration with initial Provisioning done automatically (more information below).
Our typical configuration for Grafana is included in the template.
version: "3.4"
services:
grafana:
container_name: grafana
image: ghcr.io/volkovlabs/app:latest
ports:
- 3000:3000/tcp
environment:
- GF_DEFAULT_APP_MODE=development
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/panels.json
- GF_INSTALL_PLUGINS=marcusolsson-static-datasource
volumes:
- ./dist:/var/lib/grafana/plugins/volkovlabs-abc-panel
- ./provisioning:/etc/grafana/provisioning
In this configuration, Grafana starts in Anonymous mode and does not require authentication. Any plugins can be installed at the start-up automatically.
We use the Business Input Data Source to prototype the idea and then include additional services to Docker Compose and corresponding data sources to Grafana.
Building and Signing
Before starting the Grafana container, the plugin should be built and signed in the /dist
folder. The other option is to enable the development mode.
The /dist
folder is mounted to the Grafana container in the provided configuration. Plugin signing was introduced in Grafana 7.0 and became mandatory for Grafana 8.0. Take a look at the Documentation about different signing levels.
To build and sign plugins as Private we use scripts configured in the package.json
file. When the plugin is ready to release, the signature can be updated by the Grafana team to Community or Commercial and the parameter rootUrls
can be removed.
"scripts": {
"build": "grafana-toolkit plugin:build --coverage",
"sign": "grafana-toolkit plugin:sign --rootUrls http://localhost:3000/",
},
Visual Studio Code
Scripts can be executed using the command line or Visual Studio Code, which is our preferred UI for development, and we recommend it to our clients who want to contribute and follow the process.
![Run build, sign script from the Visual Studio Code, our preferred UI for development.](/img/blog/2021-12-10-panel-template/vscode.png)
You may notice special --coverage
flag added to the build command to generate coverage files, which are uploaded and reviewed as a part of Continuous Integration (CI).
Provisioning
To make the development process repeatable, transferrable, and easier for the Grafana team to Review, we create provisioning files to add data sources, application plugins, and dashboards in the /provisioning
folder.
Here is an example of how to add a Business Input Data Source:
apiVersion: 1
datasources:
- name: Business Input
type: marcusolsson-static-datasource
access: proxy
isDefault: true
orgId: 1
version: 1
editable: true
To add or update dashboards, they should be exported as Global and placed in the /provisioning/dashboards
folder. Detailed information can be found in the Grafana Documentation.