Grafana - Import dashboard as part of docker-compose
Asked Answered
D

2

16

Is it possible to import a dashboard when building my docker image for Grafana.

My docker-compose.yml currently looks like this:

# /docker-compose.yml
version: "3"
services:
    grafana:
        image: grafana/grafana:latest
        ports: 
            - 3000:3000

Is there anything I can add there - btw the dashboard I would like to have pre setup is: https://grafana.com/grafana/dashboards/10562

Thanks.

Denham answered 21/8, 2020 at 7:33 Comment(0)
S
24

I'm using this to automatically import a dashboard to visualise my k6 load test runs:

docker-compose.yml:

services:
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
    volumes:
      - ./grafana/dashboard.yaml:/etc/grafana/provisioning/dashboards/main.yaml
      - ./grafana/dashboards:/var/lib/grafana/dashboards

grafana/dashboard.yaml:

apiVersion: 1

providers:
  - name: "Dashboard provider"
    orgId: 1
    type: file
    disableDeletion: false
    updateIntervalSeconds: 10
    allowUiUpdates: false
    options:
      path: /var/lib/grafana/dashboards
      foldersFromFilesStructure: true

grafana/dashboards/main-dashboard.json:

{
    "title": "Main Dashboard",
    "description": "A dashboard..."
    ...
}
Synn answered 3/1, 2023 at 15:2 Comment(1)
If you're interested in k6 load testing, this is the repo you can test the code above in: github.com/go-automate/k6-typescript-frameworkSynn
T
2

Provisioning a dashboard just by adding something to your YML is not possible. The way to achieve this is not that straight-forward.

Provisioning a dashboard in Grafana is generally supported and widely used. You can find the official doc here. The gist of it is that you have to use provide provisioning YMLs to grafana. In these config files you have to point to dashboard files in JSON format. You cannot point to a dashboard in the Grafana Cloud.

Therefore you will have to download the dashboard beforehand and store it. Alternatively you can of course fetch the dashboard every time you run your pipeline that deploys Grafana.

So in short, the simplest option for you:

  1. Download the dashboard manually
  2. Store it somewhere near to your docker compose YML.
  3. Create a provisioning YML according to the docs.
  4. Bind the YML to the container (I don't know your environment... directly baking it into the image is not best practice, preferably config or volume).
Takakotakakura answered 21/8, 2020 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.