Skip to content

Commit

Permalink
chore: update grafana dashboards and add backup instructions
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jboix committed Nov 12, 2024
1 parent 1b231dd commit b2de28b
Show file tree
Hide file tree
Showing 12 changed files with 539 additions and 150 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ git config core.hooksPath .githooks/
Refer to our [Contribution Guide](docs/CONTRIBUTING.md) for more detailed information.
### Exporting Dashboards from production
See the [Grafana Dashboard Export Guide](./docs/DASHBOARD_EXPORT_GUIDE.md) for information on how
to export and backup the dashboards in production.
## License
This project is licensed under the [MIT License](LICENSE).
Expand Down
79 changes: 79 additions & 0 deletions docs/DASHBOARD_EXPORT_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Grafana Dashboard Export Guide

This guide provides a method to export all dashboards within a specified folder in Grafana into a
single zip file, containing individual JSON files for each dashboard.

## Steps

### 1. Open the Browser Console

- Open your Grafana instance and log in if prompted by SSO.
- Press **F12** (or right-click and select **Inspect**) to open Developer Tools.
- Navigate to the **Console** tab.

### 2. Load JSZip Library

- To manage multiple files in a zip, we’ll use the [JSZip library](https://stuk.github.io/jszip/).
Copy and paste the following code into the console and press **Enter**:

```javascript
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js';
document.head.appendChild(script);
```

- Verify that JSZip is loaded by typing `JSZip` into the console and pressing **Enter**. You should
see an object or function returned.

### 3. Run the Export Script

- Copy and paste the following code into the console and press **Enter**:

```javascript
async function exportAllDashboardsWithFolders() {
const zip = new JSZip();

// Step 1: Get all folders
const folderResponse = await fetch(`/api/folders`);
const folders = await folderResponse.json();
const folderMap = {};
folders.forEach(folder => {
folderMap[folder.uid] = folder.title.replace(/[/\\?%*:|"<>]/g, ''); // Clean up folder names
});

// Step 2: Fetch all dashboards across folders
const response = await fetch(`/api/search?type=dash-db`);
const dashboards = await response.json();

for (const dashboard of dashboards) {
const uid = dashboard.uid;
const title = dashboard.title.replace(/[/\\?%*:|"<>]/g, ''); // Clean up filename
const folderName = folderMap[dashboard.folderUid] || 'General';

// Fetch each dashboard's JSON
const dashboardResponse = await fetch(`/api/dashboards/uid/${uid}`);
const dashboardData = await dashboardResponse.json();

// Add each dashboard JSON to the zip, organized by folder
zip.file(`${folderName}/${title}.json`, JSON.stringify(dashboardData.dashboard, null, 2));
console.log(`Added to zip: ${folderName}/${title}`);
}

// Step 3: Generate the zip and trigger download
zip.generateAsync({ type: 'blob' }).then(function (content) {
const link = document.createElement('a');
link.href = URL.createObjectURL(content);
link.download = 'grafana_dashboards.zip';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
console.log("Downloaded all dashboards as zip with folder structure.");
});
}

exportAllDashboardsWithFolders();
```
- The script will create a zip containing individual JSON files for each dashboard and will follow
Grafana folder structure.
- Each JSON file is named after the dashboard title and represents a backup of the dashboard’s
configuration.
2 changes: 1 addition & 1 deletion pillarbox-event-dispatcher
2 changes: 1 addition & 1 deletion pillarbox-monitoring-grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile for grafana
FROM grafana/grafana:11.0.0
FROM grafana/grafana:10.4.1

# Copy provisioning and dashboards
COPY ./provisioning /etc/grafana/provisioning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 3,
"links": [],
"panels": [
{
"datasource": {
"type": "grafana-opensearch-datasource",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"description": "Usage by Operating System for the selected time range.",
"fieldConfig": {
Expand Down Expand Up @@ -283,15 +284,15 @@
],
"datasource": {
"type": "opensearch",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"metrics": [
{
"id": "1",
"type": "count"
}
],
"query": "event_name:START AND data.player.platform:${platform} AND\ndata.media.id:${bu:raw}",
"query": "event_name:START \nAND data.player.platform:${platform}\nAND data.media.id:${bu:raw}",
"refId": "A",
"timeField": "@timestamp"
}
Expand All @@ -302,7 +303,7 @@
{
"datasource": {
"type": "grafana-opensearch-datasource",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"description": "Usage by device type for the selected time range.",
"fieldConfig": {
Expand Down Expand Up @@ -562,15 +563,15 @@
],
"datasource": {
"type": "opensearch",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"metrics": [
{
"id": "1",
"type": "count"
}
],
"query": "event_name:START AND data.player.platform:${platform} AND\ndata.media.id:${bu:raw}",
"query": "event_name:START\nAND data.player.platform:${platform}\nAND data.media.id:${bu:raw}",
"refId": "A",
"timeField": "@timestamp"
}
Expand All @@ -581,7 +582,7 @@
{
"datasource": {
"type": "grafana-opensearch-datasource",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"description": "Usage by browser for the selected time range.",
"fieldConfig": {
Expand Down Expand Up @@ -736,15 +737,15 @@
],
"datasource": {
"type": "opensearch",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"metrics": [
{
"id": "1",
"type": "count"
}
],
"query": "event_name:START AND data.player.platform:${platform} AND\ndata.media.id:${bu:raw}",
"query": "event_name:START\nAND data.player.platform:${platform}\nAND data.media.id:${bu:raw}",
"refId": "A",
"timeField": "@timestamp"
}
Expand All @@ -755,7 +756,7 @@
{
"datasource": {
"type": "grafana-opensearch-datasource",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"description": "The top 10 operating systems' versions for the selected time range.",
"fieldConfig": {
Expand Down Expand Up @@ -856,15 +857,15 @@
],
"datasource": {
"type": "opensearch",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"metrics": [
{
"id": "1",
"type": "count"
}
],
"query": "event_name:START AND data.player.platform:${platform} AND\ndata.media.id:${bu:raw}",
"query": "event_name:START\nAND data.player.platform:${platform}\nAND data.media.id:${bu:raw}",
"refId": "A",
"timeField": "@timestamp"
}
Expand Down Expand Up @@ -938,7 +939,7 @@
{
"datasource": {
"type": "grafana-opensearch-datasource",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"description": "The top 10 device models for the selected time range.",
"fieldConfig": {
Expand Down Expand Up @@ -1033,15 +1034,15 @@
],
"datasource": {
"type": "opensearch",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"metrics": [
{
"id": "1",
"type": "count"
}
],
"query": "event_name:START AND data.player.platform:${platform} AND\ndata.media.id:${bu:raw}",
"query": "event_name:START\nAND data.player.platform:${platform}\nAND data.media.id:${bu:raw}",
"refId": "A",
"timeField": "@timestamp"
}
Expand All @@ -1052,7 +1053,7 @@
{
"datasource": {
"type": "grafana-opensearch-datasource",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"description": "The top 10 browsers' versions for the selected time range.",
"fieldConfig": {
Expand Down Expand Up @@ -1153,15 +1154,15 @@
],
"datasource": {
"type": "opensearch",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"metrics": [
{
"id": "1",
"type": "count"
}
],
"query": "event_name:START AND data.player.platform:${platform} AND\ndata.media.id:${bu:raw}",
"query": "event_name:START\nAND data.player.platform:${platform}\nAND data.media.id:${bu:raw}",
"refId": "A",
"timeField": "@timestamp"
}
Expand Down Expand Up @@ -1239,14 +1240,15 @@
"templating": {
"list": [
{
"allValue": "*",
"current": {
"selected": false,
"text": "All",
"value": "$__all"
},
"datasource": {
"type": "opensearch",
"uid": "de0gi09a14ow0e"
"uid": "PB728120E9B299770"
},
"definition": "{\n \"find\": \"terms\",\n \"field\": \"data.player.platform.keyword\",\n \"size\": 1000\n}",
"description": "Filter by player platform.",
Expand All @@ -1257,7 +1259,7 @@
"name": "platform",
"options": [],
"query": "{\n \"find\": \"terms\",\n \"field\": \"data.player.platform.keyword\",\n \"size\": 1000\n}",
"refresh": 1,
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 1,
Expand Down Expand Up @@ -1318,11 +1320,10 @@
"from": "now-1h",
"to": "now"
},
"timeRangeUpdatedDuringEditOrView": false,
"timepicker": {},
"timezone": "browser",
"title": "Device Breakdown",
"uid": "cdrj6qnc10veoe",
"version": 1,
"version": 6,
"weekStart": ""
}
Loading

0 comments on commit b2de28b

Please sign in to comment.