This repository contains an example of a Grafana dashboard as code, defined with Grafonnet, continuously deployed to a Grafana Cloud instance, thanks to Grizzly and GitHub Actions.
- An example dashboard written in Jsonnet with Grafonnet.
- Are you willing to extend it? Find here the Grafonnet API for dashboards.
- An example of how to use Grizzle to push dashboards to a Grafana instance.
- Would you like to learn more about Grizzly? Find here the docs.
- An example of how to continuously deploy Grafonnet code to a Grafana instance with GitHub Actions.
If you're a learning-by-doing kind of person, you can follow the steps below to build your own example.
First of all, you need to have these tools up and running before starting:
- Jsonnet (go-jsonnet flavor)
- jsonnet-bundler
- Grafana Cloud instance (with a service account token with enough permissions - e.g. admin)
-
Initialize a new project:
jb init
-
Add Grafonnet as dependency:
jb install github.com/grafana/grafonnet/gen/grafonnet-latest@main
-
Create an
example.jsonnet
file with a basic dashboard:local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'; g.dashboard.new('Grafonnet example') + g.dashboard.withDescription('Example dashboard built with Grafonnet')
-
Create a
dashboards.libsonnet
file with the main definition:{ grafanaDashboards+:: { 'example.json': (import 'example.jsonnet'), }, }
NOTE: It basically imports the example dashboard we defined in the previous step
-
Set up Grafana auth for Grizzly as Actions secrets:
GRAFANA_URL
with the root url of your instanceGRAFANA_TOKEN
with your service account token
-
Set up GitHub Actions to automatically
grr apply
your changes on every push tomain
:# .github/workflows/deploy.yml name: deploy on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest container: image: grafana/grizzly:0.2.1-amd64 env: GRAFANA_URL: ${{ secrets.GRAFANA_URL }} GRAFANA_TOKEN: ${{ secrets.GRAFANA_TOKEN }} steps: - name: Check out code uses: actions/checkout@v3 - name: Deploy dashboards run: grr apply dashboards.libsonnet -l debug
-
Push new changes on
example.jsonnet
tomain
and enjoy!
Have you detected a typo or something incorrect, and you are willing to contribute?
Please, open a pull request, and I'll be happy to review it.