Skip to content

Commit 1497c96

Browse files
jboixdefagosMGaetan89
committed
chore: update grafana dashboards and add backup instructions
Resolves #3 by removing severity filters from Grafana dashboards. Changes made: - Added backing up instructions under `docs/DASHBOARD_EXPORT_GUIDE.md` - Updated submodules to latest version. - Updated dashboards in provisioning to align with production state. - Adapted Grafana version in Dockerfile for consistent local testing. - Use aliased index in datasource provisioning (see SRGSSR/pillarbox-monitoring-transfer#16) Co-authored-by: Samuel Défago <[email protected]> Co-authored-by: Gaëtan Muller <[email protected]>
1 parent 1b231dd commit 1497c96

13 files changed

+1701
-192
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ git config core.hooksPath .githooks/
166166
167167
Refer to our [Contribution Guide](docs/CONTRIBUTING.md) for more detailed information.
168168
169+
### Exporting Dashboards from production
170+
171+
See the [Grafana Dashboard Export Guide](./docs/DASHBOARD_EXPORT_GUIDE.md) for information on how
172+
to export and backup the dashboards in production.
173+
169174
## License
170175
171176
This project is licensed under the [MIT License](LICENSE).

docs/DASHBOARD_EXPORT_GUIDE.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Grafana Dashboard Export Guide
2+
3+
This guide provides step-by-step instructions to export dashboards from Grafana. You can export
4+
either a single dashboard directly through the Grafana interface or all dashboards within a
5+
specified folder using a custom script.
6+
7+
## Exporting a Single Dashboard
8+
9+
To export an individual dashboard directly through the Grafana interface, follow these steps:
10+
11+
1. Open the dashboard you wish to export.
12+
2. Click the Share button (usually located at the top right).
13+
3. In the Share panel, navigate to the Export tab.
14+
4. Select Save to file. This will download a JSON file of the dashboard's configuration to your
15+
computer.
16+
17+
## Exporting All Dashboards in a Folder
18+
19+
The following steps outline a method to export all dashboards within a specified folder in Grafana
20+
as a single zip file containing individual JSON files for each dashboard.
21+
22+
### 1. Open the Browser Console
23+
24+
- Open your Grafana instance and log in if prompted by SSO.
25+
- Press <kbd>F12</kbd> (or right-click and select **Inspect**) to open Developer Tools.
26+
- Navigate to the **Console** tab.
27+
28+
### 2. Load JSZip Library
29+
30+
- To manage multiple files in a zip, we’ll use the [JSZip library](https://stuk.github.io/jszip/).
31+
Copy and paste the following code into the console and press <kbd>Enter</kbd>:
32+
33+
```javascript
34+
var script = document.createElement('script');
35+
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js';
36+
document.head.appendChild(script);
37+
```
38+
39+
- Verify that JSZip is loaded by typing `JSZip` into the console and pressing <kbd>Enter</kbd>. You
40+
should
41+
see an object or function returned.
42+
43+
### 3. Run the Export Script
44+
45+
- Copy and paste the following code into the console and press <kbd>Enter</kbd>:
46+
47+
```javascript
48+
async function exportAllDashboardsWithFolders() {
49+
const zip = new JSZip();
50+
51+
// Step 1: Get all folders
52+
const folderResponse = await fetch(`/api/folders`);
53+
const folders = await folderResponse.json();
54+
const folderMap = {};
55+
folders.forEach(folder => {
56+
folderMap[folder.uid] = folder.title.replace(/[/\\?%*:|"<>]/g, ''); // Clean up folder names
57+
});
58+
59+
// Step 2: Fetch all dashboards across folders
60+
const response = await fetch(`/api/search?type=dash-db`);
61+
const dashboards = await response.json();
62+
63+
for (const dashboard of dashboards) {
64+
const uid = dashboard.uid;
65+
const title = dashboard.title.replace(/[/\\?%*:|"<>]/g, ''); // Clean up filename
66+
const folderName = folderMap[dashboard.folderUid] || 'General';
67+
68+
// Fetch each dashboard's JSON
69+
const dashboardResponse = await fetch(`/api/dashboards/uid/${uid}`);
70+
const dashboardData = await dashboardResponse.json();
71+
72+
// Add each dashboard JSON to the zip, organized by folder
73+
zip.file(`${folderName}/${title}.json`, JSON.stringify(dashboardData.dashboard, null, 2));
74+
console.log(`Added to zip: ${folderName}/${title}`);
75+
}
76+
77+
// Step 3: Generate the zip and trigger download
78+
zip.generateAsync({ type: 'blob' }).then(function (content) {
79+
const link = document.createElement('a');
80+
link.href = URL.createObjectURL(content);
81+
link.download = 'grafana_dashboards.zip';
82+
document.body.appendChild(link);
83+
link.click();
84+
document.body.removeChild(link);
85+
console.log("Downloaded all dashboards as zip with folder structure.");
86+
});
87+
}
88+
89+
exportAllDashboardsWithFolders();
90+
```
91+
- The script will create a zip containing individual JSON files for each dashboard and will follow
92+
Grafana folder structure.
93+
- Each JSON file is named after the dashboard title and represents a backup of the dashboard’s
94+
configuration.

pillarbox-monitoring-grafana/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Dockerfile for grafana
2-
FROM grafana/grafana:11.0.0
2+
FROM grafana/grafana:10.4.1
33

44
# Copy provisioning and dashboards
55
COPY ./provisioning /etc/grafana/provisioning

0 commit comments

Comments
 (0)