简体   繁体   English

Grafana - 导入仪表板作为 docker-compose 的一部分

[英]Grafana - Import dashboard as part of docker-compose

Is it possible to import a dashboard when building my docker image for Grafana.在为 Grafana 构建我的 docker 图像时是否可以导入仪表板。

My docker-compose.yml currently looks like this:我的docker-compose.yml目前看起来是这样的:

# /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有什么我可以在那里添加的 - 顺便说一下,我想预先设置的仪表板是: https://grafana.com/grafana/dashboards/10562

Thanks.谢谢。

Provisioning a dashboard just by adding something to your YML is not possible.仅通过向 YML 添加内容来配置仪表板是不可能的。 The way to achieve this is not that straight-forward.实现这一目标的方法并不是那么简单。

Provisioning a dashboard in Grafana is generally supported and widely used.通常支持并广泛使用在 Grafana 中配置仪表板 You can find the official doc here .您可以在此处找到官方文档。 The gist of it is that you have to use provide provisioning YMLs to grafana.它的要点是你必须使用提供配置 YMLs 到 grafana。 In these config files you have to point to dashboard files in JSON format.在这些配置文件中,您必须指向 JSON 格式的仪表板文件。 You cannot point to a dashboard in the Grafana Cloud.您不能指向 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.或者,您当然可以在每次运行部署 Grafana 的管道时获取仪表板。

So in short, the simplest option for you:简而言之,最简单的选择是:

  1. Download the dashboard manually手动下载仪表板
  2. Store it somewhere near to your docker compose YML.将它存储在您的 docker 撰写 YML 附近的某个地方。
  3. Create a provisioning YML according to the docs.根据文档创建配置 YML。
  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).将 YML 绑定到容器(我不知道你的环境......直接将其烘焙到图像中不是最佳实践,最好是配置或卷)。

I'm using this to automatically import a dashboard to visualise my k6 load test runs:我正在使用它来自动导入仪表板以可视化我的k6负载测试运行:

docker-compose.yml : 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 : 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 : grafana/dashboards/main-dashboard.json

{
    "title": "Main Dashboard",
    "description": "A dashboard..."
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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