简体   繁体   中英

Grafana - Import dashboard as part of docker-compose

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.

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).

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..."
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM