Hi Team,
referring to the following documentation Provision Grafana | Grafana documentation
I want to create a grafana dashboard and datasource through a docker file , where datasource is working but the dashboard isn’t working, dashboard is not reflected on the grafana UI.
use case is to easily deploy the dashboard from the backend rather adding it from the frontend grafana UI.
sharing you the Dockerfile
choose a base image
FROM grafana/grafana:latest
Set environment variables for provisioning
ENV GF_SECURITY_ADMIN_PASSWORD=admin
ENV GF_SECURITY_ADMIN_USER=admin
#ENV GF_PATHS_PROVISIONING=/etc/grafana/provisioning
COPY datasources/ /etc/grafana/provisioning/datasources/
COPY dashboards/ /etc/grafana/provisioning/dashboards/
EXPOSE 3000
folder structure
- dashboards
/dashboard.yaml
/dashboard.json - datasources
/datasource.yaml - Dockerfile
where datasource folder consists of datasource.yaml file
following code for datasource.yaml file was
apiVersion: 1
datasources:
- name: MySQL
type: mysql
access: proxy
url: ****:3306
database: monitor
user: monitor
secureJsonData:
password: *******
isDefault: true
jsonData:
timeInterval: “60s”
editable: true
In dashboard i had two folders one is databoard.json and dashboard.yaml
dashboard.yaml has the following code
apiVersion: 1
providers:
- name: ‘default’
orgId: 1
folder: ‘’
type: file
disableDeletion: false
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards
dashboard.json has following code
{
“dashboard”: {
“id”: null,
“uid”: “12345666”,
“title”: “My new Dashboard”,
“panels”: [
{
“title”: “Panel 1”,
“type”: “graph”,
“datasource”: “MySQL”,
“targets”: [
{
“expr”: “SELECT months.month AS month, COALESCE(AVG(yt.ram_usage), 0) AS ram_usage, COALESCE(AVG(yt.cpu_usage), 0) AS cpu_usage FROM ( SELECT ‘01’ AS month UNION SELECT ‘02’ UNION SELECT ‘03’ UNION SELECT ‘04’ UNION SELECT ‘05’ UNION SELECT ‘06’ UNION SELECT ‘07’ UNION SELECT ‘08’ UNION SELECT ‘09’ UNION SELECT ‘10’ UNION SELECT ‘11’ UNION SELECT ‘12’ ) AS months LEFT JOIN ( SELECT DATE_FORMAT(FROM_UNIXTIME(created_at), ‘%m’) AS month, AVG(ram_usage) AS ram_usage, AVG(cpu_usage) AS cpu_usage FROM system_performance WHERE DATE_FORMAT(FROM_UNIXTIME(created_at), ‘%Y’) = ‘2023’ AND DATE_FORMAT(FROM_UNIXTIME(created_at), ‘%Y-%m’) <= DATE_FORMAT(NOW(), ‘%Y-%m’) GROUP BY month ) AS yt ON months.month = yt.month GROUP BY month;”,
“interval”: “60s”,
“format”: “bar_chart”
}
]
}
],
“time”: {
“from”: “now-6h”,
“to”: “now”
}
},
“version”: 0
}
Thanks,
dev