如何保存 Grafana 容器的仪表板 YAML,以便在创建时加载?
docker-compose.yml:
grafana:
image: grafana/grafana
container_name: grafana
volumes:
- ./grafana-datasource.yml:/etc/grafana/provisioning/datasources/datasource.yaml
- ./dashboard.yml:/etc/grafana/provisioning/dashboards/dashboard.yaml
- ./grafana/provisioning/dashboards/:/etc/grafana/provisioning/dashboards/
ports:
- "3000:3000"
depends_on:
- prometheus
仪表板.yml:
apiVersion: 1
providers:
# <string> an unique provider name
- name: 'a unique provider name'
# <int> org id. will default to orgId 1 if not specified
orgId: 1
# <string, required> name of the dashboard folder. Required
folder: ''
# <string> folder UID. will be automatically generated if not specified
folderUid: ''
# <string, required> provider type. Required
type: file
# <bool> disable dashboard deletion
disableDeletion: false
# <bool> enable dashboard editing
editable: true
# <int> how often Grafana will scan for changed dashboards
updateIntervalSeconds: 10
options:
# <string, required> path to dashboard files on disk. Required
path: /etc/grafana/provisioning/dashboards
Grafana容器错误:
t=2019-08-30T18:13:58+0000 lvl=eror msg="Server shutdown" logger=server reason="Service init failed: Failed to create provisioner: Failed to read dashboards config: could not parse provisioning config file: dashboard-prometheus-yml.yaml error: yaml: unmarshal errors:\n line 1: cannot unmarshal !!map into []*dashboards.DashboardsAsConfigV0"
谢谢你!
答案1
作为文件和目录进行访问可能会发生冲突/etc/grafana/provisioning/dashboards
。这是对我有用的配置。
version: '3.4'
services:
grafana:
image: grafana/grafana
container_name: grafana
volumes:
- ./datasources:/etc/grafana/provisioning/datasources/
- ./dashboards:/etc/grafana/provisioning/dashboards/
ports:
- "3000:3000"
仪表板.yaml
apiVersion: 1
providers:
# <string> an unique provider name
- name: 'a unique provider name'
# <int> org id. will default to orgId 1 if not specified
orgId: 1
# <string, required> name of the dashboard folder. Required
folder: ''
# <string> folder UID. will be automatically generated if not specified
folderUid: ''
# <string, required> provider type. Required
type: file
# <bool> disable dashboard deletion
disableDeletion: false
# <bool> enable dashboard editing
editable: true
# <int> how often Grafana will scan for changed dashboards
updateIntervalSeconds: 10
options:
# <string, required> path to dashboard files on disk. Required
path: /etc/grafana/provisioning/dashboards
那么相应的文件夹结构是
docker-compose.yaml
datasources/
dashboards/
dashboard.yaml
my-dashboard.json
my-dashboard.json 是作为儿子导出的 Grafana 仪表板。