Skip to main content

Importing and Exporting Dashboards

1. Importing Dashboard from JSON

Step Description Action
1 Go to Grafana dashboard page Click on + button or navigate to /dashboards
2 Select Import option Click on Import from the top menu or dashboard list
3 Upload JSON file Click Browse and select the dashboard JSON file
4 Map data sources Select appropriate data sources from dropdowns
5 Review and apply Click Import to finalize the dashboard creation

Example: Importing a dashboard from JSON

{
  "dashboard": {
    "title": "System Metrics Dashboard",
    "panels": [
      {
        "id": 1,
        "type": "graph",
        "title": "CPU Usage"
      }
    ]
  },
  "overwrite": true
}
Note: Ensure the JSON file is valid and compatible with your Grafana version.
Warning: Importing with overwrite set to true will replace existing dashboards with the same name.

2. Importing Dashboard by ID

Property Value Description
dashboardId string The unique identifier of the dashboard to import
folderId number The folder ID where the dashboard will be imported (optional)
overwrite boolean If true, overwrites existing dashboard with same name (default: false)

Example: Importing Dashboard by ID

const importDashboard = async () => {
  const response = await fetch('/api/dashboards/db', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer <your-api-token>'
    },
    body: JSON.stringify({
      dashboard: {
        id: 'dashboard-id-here',
        title: 'My Imported Dashboard'
      },
      folderId: 1,
      overwrite: true
    })
  });

  const result = await response.json();
  console.log('Dashboard imported:', result);
};
Note: The dashboard ID can be found in the URL when viewing a dashboard or through the Grafana API.

3. Exporting Dashboard as JSON

Option Values Notes
dashboard object JSON object representing the dashboard configuration
folderId number Folder ID where the dashboard is stored (optional)
overwrite boolean If true, overwrites existing dashboard with same name (default: false)

Example: Exporting Dashboard as JSON

const dashboard = {
  "dashboard": {
    "id": null,
    "title": "My Dashboard",
    "panels": [
      {
        "id": 1,
        "type": "graph",
        "title": "CPU Usage"
      }
    ]
  },
  "folderId": 0,
  "overwrite": false
};

// Export dashboard to JSON file
console.log(JSON.stringify(dashboard, null, 2));
Note: The exported JSON includes all panel configurations, variables, and other dashboard metadata.

4. Sharing Dashboard Externally

Option Values Description
dashboard.id 12345 Unique identifier for the dashboard
dashboard.uid abc123def456 Unique ID used in URLs and API calls
dashboard.title System Metrics Title of the dashboard
dashboard.url /d/abc123def456/system-metrics Public URL to access the dashboard

Example: Exporting Dashboard JSON

{
  "dashboard": {
    "id": 12345,
    "uid": "abc123def456",
    "title": "System Metrics",
    "url": "/d/abc123def456/system-metrics"
  },
  "overwrite": true
}
Note: The dashboard URL can be shared publicly or restricted to specific users depending on Grafana's access control settings.
Warning: Sharing dashboards externally may expose sensitive data. Ensure appropriate permissions and data masking are in place.

5. Exporting Dashboard for Provisioning

Option Values Notes
dashboard.id 12345 Unique identifier for the dashboard
dashboard.uid abc123def456 Unique ID used in URLs and API calls
dashboard.title "Production Metrics" Dashboard title as displayed in Grafana
dashboard.folderId 0 Folder ID where the dashboard is stored (0 = General)
dashboard.folderUid null Folder UID if dashboard is in a specific folder
dashboard.datasource "Prometheus" Name of the data source used
dashboard.timezone "browser" Timezone setting for the dashboard
dashboard.refresh "5m" Auto-refresh interval (e.g., "10s", "1m")
dashboard.schemaVersion 36 Schema version used for dashboard JSON
dashboard.version 1 Version number for the dashboard

Example: Exported Dashboard JSON

{
  "dashboard": {
    "id": 12345,
    "uid": "abc123def456",
    "title": "Production Metrics",
    "folderId": 0,
    "folderUid": null,
    "datasource": "Prometheus",
    "timezone": "browser",
    "refresh": "5m",
    "schemaVersion": 36,
    "version": 1
  }
}
Note: When exporting a dashboard for provisioning, ensure that all variables and data sources referenced in the dashboard are properly configured in the target environment.

6. Using Dashboard Templates

Property Description Example
dashboard.title Title of the dashboard template "My Dashboard Template"
dashboard.uid Unique identifier for the dashboard "my-dashboard-template-uid"
dashboard.panels Array of panel definitions [{...}]
dashboard.templating.list Template variables configuration [{...}]

Example: Creating a Dashboard Template

{
  "dashboard": {
    "title": "Infrastructure Overview",
    "uid": "infrastructure-overview-123",
    "templating": {
      "list": [
        {
          "name": "host",
          "label": "Host",
          "query": "label_values(up, instance)",
          "current": {
            "text": "localhost:9090",
            "value": "localhost:9090"
          }
        }
      ]
    },
    "panels": [
      {
        "title": "CPU Usage",
        "type": "graph",
        "targets": [
          {
            "expr": "rate(node_cpu_seconds_total{instance=\"$host\"}[5m])"
          }
        ]
      }
    ]
  }
}
Note: Dashboard templates can be imported via the Grafana UI or using the grafana-cli command-line tool.
Warning: Ensure that all variable names and panel IDs are unique when using templates to avoid conflicts during import.

7. Importing with Data Source Mapping

When importing a dashboard into Grafana, you might need to remap data sources if the original dashboard was created with a different data source name or type than what's available in your current Grafana instance.

Field Description Example
datasourceUid Unique identifier of the data source in the target Grafana instance 12345678-1234-1234-1234-123456789012
originalDatasourceUid Unique identifier of the data source in the original dashboard abcdef12-3456-7890-abcd-ef1234567890

Example: Mapping Data Sources During Import

{
  "dashboard": {
    "title": "My Dashboard",
    "uid": "my-dashboard-uid"
  },
  "overwrite": true,
  "inputs": [
    {
      "name": "datasource",
      "label": "Data Source",
      "description": "Select the data source to use for this dashboard",
      "pluginId": "grafana-postgres-datasource",
      "value": "12345678-1234-1234-1234-123456789012"
    }
  ]
}
Note: Ensure that the data source UIDs match between the original and target environments to avoid broken panels.
Warning: If a data source is not found in the target environment, the dashboard may fail to load or display incorrect data.

8. Creating Dashboard Snapshots

Dashboard snapshots allow you to share a read-only view of your Grafana dashboard with others, even if they don't have access to the Grafana instance.

Property Description Default Value
name Name of the snapshot Snapshot
expires Expiration time in seconds (0 = never expires) 0
externalUrl External URL to access the snapshot Generated automatically

Example: Creating a Snapshot via API

const snapshot = {
  name: "Production Metrics",
  expires: 3600,
  dashboard: {
    id: 12345,
    uid: "abc123"
  }
};

fetch("/api/snapshots", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify(snapshot)
})
.then(response => response.json())
.then(data => console.log("Snapshot URL:", data.url));
Note: Snapshots are stored in the Grafana database and can be managed through the UI or API.

9. Sharing Dashboard Snapshots

Property Value Description
snapshot.name string Name of the snapshot
snapshot.expires number Expiration time in seconds (default: 2592000 = 30 days)
snapshot.hideAnnotations boolean Hide annotations from the snapshot
snapshot.hideControls boolean Hide controls from the snapshot

Example: Create a Snapshot

const snapshot = {
  name: "Production Metrics",
  expires: 86400,
  hideAnnotations: true,
  hideControls: false
};

// Send to Grafana API endpoint:
// POST /api/snapshots
Note: Snapshots are public by default and can be accessed by anyone with the URL.
Warning: Do not include sensitive data in snapshots as they are publicly accessible.

10. Deleting Dashboard Snapshots

Property Description Values
snapshotId Unique identifier for the dashboard snapshot string
deleted Indicates whether the snapshot was successfully deleted boolean

Example: Delete a Dashboard Snapshot

const snapshotId = "abc123";

// Delete the snapshot using Grafana API
fetch(`/api/snapshots/${snapshotId}`, {
  method: "DELETE",
  headers: {
    "Authorization": "Bearer <your-api-token>"
  }
})
.then(response => {
  if (response.ok) {
    console.log("Snapshot deleted successfully");
  } else {
    console.error("Failed to delete snapshot");
  }
});
Note: Ensure you have the necessary permissions to delete dashboard snapshots. Snapshots can only be deleted by users with appropriate access rights.

Was this article helpful?