Well, when you create a snapshot through API you must provide the data - Grafana will not automatically query the data when you create a snapshot.
For example, I created a snapshot of the following dashboard (removed all panels except one before creating snapshot) and publishing it to snapshot.raintank.io.
Using chrome dev tools this is what happens in browser when creating a snapshot and publishing it to snapshot.raintank.io from Grafana UI:
- When sending HTTP POST to https://snapshots-origin.raintank.io/api/snapshots the browser will first automatically send a HTTP OPTIONS request to https://snapshots-origin.raintank.io/api/snapshots to negotiate CORS.
- The HTTP OPTIONS response returns the following headers which tells the browser that a HTTP POST request is allowed to be made from any origin (browser)
Access-Control-Allow-Headers: Content-Type, Origin, Accept, User-Agent, Cache-Control, Keep-Alive
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin: *
- The actual HTTP POST is sent to https://snapshots-origin.raintank.io/api/snapshots (see request/response below). As you can see the actual data is included in snapshotData properties in the body.
Request body
{
"dashboard": {
"annotations": {
"enable": false,
"list": [
{
"name": "Annotations & Alerts",
"enable": true,
"iconColor": "rgba(0, 211, 255, 1)",
"snapshotData": [],
"type": "dashboard",
"builtIn": 1,
"hide": true
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 1,
"id": 3,
"links": [],
"panels": [
{
"aliasColors": {
"web_server_01": "#badff4",
"web_server_02": "#5195ce",
"web_server_03": "#1f78c1",
"web_server_04": "#0a437c"
},
"annotate": { "enable": false },
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"editable": true,
"fill": 6,
"grid": { "max": null, "min": 0 },
"gridPos": { "h": 11, "w": 16, "x": 0, "y": 0 },
"id": 2,
"interactive": true,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"legend_counts": true,
"lines": true,
"linewidth": 1,
"nullPointMode": "connected",
"options": false,
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"resolution": 100,
"scale": 1,
"seriesOverrides": [],
"snapshotData": [
{
"datapoints": [
[27.650000000000002, 1535370450000],
[28.950000000000003, 1535370460000],
[29, 1535370470000],
[27.9, 1535370480000],
[28.200000000000003, 1535370490000],
[27.900000000000002, 1535370500000],
[27.450000000000003, 1535370510000],
[28.5, 1535370520000],
[28.55, 1535370530000],
[25.55, 1535370540000],
[26.3, 1535370550000],
[28.700000000000003, 1535370560000],
[27.450000000000003, 1535370570000],
[27.15, 1535370580000],
[27.05, 1535370590000],
[25.85, 1535370600000],
[26.85, 1535370610000],
[27.35, 1535370620000],
[29.1, 1535370630000],
[30.900000000000002, 1535370640000],
[29.300000000000004, 1535370650000],
[27.5, 1535370660000],
[25.950000000000003, 1535370670000],
[25.35, 1535370680000],
[25.150000000000002, 1535370690000],
[25.6, 1535370700000],
[27.6, 1535370710000],
[27.75, 1535370720000],
[28.35, 1535370730000],
[30.75, 1535370740000]
],
"target": "web_server_01"
},
{
"datapoints": [
[26.85, 1535370450000],
[28.6, 1535370460000],
[28.950000000000003, 1535370470000],
[28.65, 1535370480000],
[28.75, 1535370490000],
[29.050000000000004, 1535370500000],
[28.6, 1535370510000],
[26.4, 1535370520000],
[26.450000000000003, 1535370530000],
[25.550000000000004, 1535370540000],
[26.200000000000003, 1535370550000],
[29.6, 1535370560000],
[29.15, 1535370570000],
[27.05, 1535370580000],
[26.450000000000003, 1535370590000],
[25.200000000000003, 1535370600000],
[25.5, 1535370610000],
[27.6, 1535370620000],
[31.25, 1535370630000],
[31.200000000000003, 1535370640000],
[27.400000000000002, 1535370650000],
[27.050000000000004, 1535370660000],
[27, 1535370670000],
[25.5, 1535370680000],
[26.200000000000003, 1535370690000],
[26.5, 1535370700000],
[25.700000000000003, 1535370710000],
[28.150000000000002, 1535370720000],
[29.6, 1535370730000],
[29.75, 1535370740000]
],
"target": "web_server_02"
},
{
"datapoints": [
[28.75, 1535370450000],
[29.8, 1535370460000],
[28.9, 1535370470000],
[28.450000000000003, 1535370480000],
[28.05, 1535370490000],
[28.35, 1535370500000],
[29.300000000000004, 1535370510000],
[26.550000000000004, 1535370520000],
[25.400000000000002, 1535370530000],
[25.3, 1535370540000],
[26.200000000000003, 1535370550000],
[26.900000000000002, 1535370560000],
[26.85, 1535370570000],
[28.55, 1535370580000],
[28.55, 1535370590000],
[25.4, 1535370600000],
[25.200000000000003, 1535370610000],
[27, 1535370620000],
[29.05, 1535370630000],
[30.55, 1535370640000],
[27.700000000000003, 1535370650000],
[28.1, 1535370660000],
[28, 1535370670000],
[25.700000000000003, 1535370680000],
[25.05, 1535370690000],
[25.8, 1535370700000],
[26.9, 1535370710000],
[26.9, 1535370720000],
[29.9, 1535370730000],
[31.1, 1535370740000]
],
"target": "web_server_03"
},
{
"datapoints": [
[25.950000000000003, 1535370450000],
[26.6, 1535370460000],
[27.300000000000004, 1535370470000],
[28.25, 1535370480000],
[30.3, 1535370490000],
[31.200000000000003, 1535370500000],
[30.200000000000003, 1535370510000],
[28.5, 1535370520000],
[28.6, 1535370530000],
[29.450000000000003, 1535370540000],
[27.6, 1535370550000],
[27.4, 1535370560000],
[27.700000000000003, 1535370570000],
[28.75, 1535370580000],
[29.450000000000003, 1535370590000],
[28.200000000000003, 1535370600000],
[28.550000000000004, 1535370610000],
[27.150000000000002, 1535370620000],
[25.6, 1535370630000],
[27.450000000000003, 1535370640000],
[26.9, 1535370650000],
[26.05, 1535370660000],
[26.450000000000003, 1535370670000],
[25.75, 1535370680000],
[26.700000000000003, 1535370690000],
[28.35, 1535370700000],
[27.35, 1535370710000],
[26.25, 1535370720000],
[28.05, 1535370730000],
[30.950000000000003, 1535370740000]
],
"target": "web_server_04"
}
],
"spaceLength": 10,
"spyable": true,
"stack": true,
"steppedLine": false,
"targets": [],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"timezone": "browser",
"title": "server requests",
"tooltip": {
"msResolution": false,
"query_as_alias": true,
"shared": true,
"sort": 0,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": { "buckets": null, "mode": "time", "name": null, "show": true, "values": [] },
"yaxes": [
{ "format": "short", "logBase": 1, "max": null, "min": null, "show": true },
{ "format": "short", "logBase": 1, "max": null, "min": null, "show": true }
],
"yaxis": { "align": false, "alignLevel": null },
"zerofill": true,
"links": []
}
],
"refresh": false,
"schemaVersion": 16,
"snapshot": { "timestamp": "2018-08-27T11:52:22.450Z" },
"style": "dark",
"tags": ["demo"],
"templating": { "list": [] },
"time": {
"from": "2018-08-27T11:47:26.458Z",
"to": "2018-08-27T11:52:26.459Z",
"raw": { "from": "now-5m", "to": "now" }
},
"timepicker": {
"collapse": false,
"enable": true,
"notice": false,
"now": true,
"refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"],
"status": "Stable",
"time_options": ["5m", "15m", "1h", "2h", " 6h", "12h", "24h", "2d", "7d", "30d"],
"type": "timepicker"
},
"timezone": "browser",
"title": "Big Dashboard",
"uid": "000000003",
"version": 16
},
"name": "Big Dashboard",
"expires": 0
}
Response body
{
"deleteKey": "<delete key>",
"deleteUrl": "https://snapshot.raintank.io/api/snapshots-delete/<delete key>",
"key": "<access key>",
"url": "https://snapshot.raintank.io/dashboard/snapshot/<access key>"
}
- Another HTTP POST is sent to https://play.grafana.org/api/snapshots/ (see request/response below).
Request body
{
"dashboard": {
"annotations": {
"enable": false,
"list": [
{
"name": "Annotations & Alerts",
"enable": true,
"iconColor": "rgba(0, 211, 255, 1)",
"snapshotData": [],
"type": "dashboard",
"builtIn": 1,
"hide": true
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 1,
"id": 3,
"links": [],
"panels": [
{
"aliasColors": {
"web_server_01": "#badff4",
"web_server_02": "#5195ce",
"web_server_03": "#1f78c1",
"web_server_04": "#0a437c"
},
"annotate": { "enable": false },
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"editable": true,
"fill": 6,
"grid": { "max": null, "min": 0 },
"gridPos": { "h": 11, "w": 16, "x": 0, "y": 0 },
"id": 2,
"interactive": true,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"legend_counts": true,
"lines": true,
"linewidth": 1,
"nullPointMode": "connected",
"options": false,
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"resolution": 100,
"scale": 1,
"seriesOverrides": [],
"snapshotData": [
{
"datapoints": [
[27.650000000000002, 1535370450000],
[28.950000000000003, 1535370460000],
[29, 1535370470000],
[27.9, 1535370480000],
[28.200000000000003, 1535370490000],
[27.900000000000002, 1535370500000],
[27.450000000000003, 1535370510000],
[28.5, 1535370520000],
[28.55, 1535370530000],
[25.55, 1535370540000],
[26.3, 1535370550000],
[28.700000000000003, 1535370560000],
[27.450000000000003, 1535370570000],
[27.15, 1535370580000],
[27.05, 1535370590000],
[25.85, 1535370600000],
[26.85, 1535370610000],
[27.35, 1535370620000],
[29.1, 1535370630000],
[30.900000000000002, 1535370640000],
[29.300000000000004, 1535370650000],
[27.5, 1535370660000],
[25.950000000000003, 1535370670000],
[25.35, 1535370680000],
[25.150000000000002, 1535370690000],
[25.6, 1535370700000],
[27.6, 1535370710000],
[27.75, 1535370720000],
[28.35, 1535370730000],
[30.75, 1535370740000]
],
"target": "web_server_01"
},
{
"datapoints": [
[26.85, 1535370450000],
[28.6, 1535370460000],
[28.950000000000003, 1535370470000],
[28.65, 1535370480000],
[28.75, 1535370490000],
[29.050000000000004, 1535370500000],
[28.6, 1535370510000],
[26.4, 1535370520000],
[26.450000000000003, 1535370530000],
[25.550000000000004, 1535370540000],
[26.200000000000003, 1535370550000],
[29.6, 1535370560000],
[29.15, 1535370570000],
[27.05, 1535370580000],
[26.450000000000003, 1535370590000],
[25.200000000000003, 1535370600000],
[25.5, 1535370610000],
[27.6, 1535370620000],
[31.25, 1535370630000],
[31.200000000000003, 1535370640000],
[27.400000000000002, 1535370650000],
[27.050000000000004, 1535370660000],
[27, 1535370670000],
[25.5, 1535370680000],
[26.200000000000003, 1535370690000],
[26.5, 1535370700000],
[25.700000000000003, 1535370710000],
[28.150000000000002, 1535370720000],
[29.6, 1535370730000],
[29.75, 1535370740000]
],
"target": "web_server_02"
},
{
"datapoints": [
[28.75, 1535370450000],
[29.8, 1535370460000],
[28.9, 1535370470000],
[28.450000000000003, 1535370480000],
[28.05, 1535370490000],
[28.35, 1535370500000],
[29.300000000000004, 1535370510000],
[26.550000000000004, 1535370520000],
[25.400000000000002, 1535370530000],
[25.3, 1535370540000],
[26.200000000000003, 1535370550000],
[26.900000000000002, 1535370560000],
[26.85, 1535370570000],
[28.55, 1535370580000],
[28.55, 1535370590000],
[25.4, 1535370600000],
[25.200000000000003, 1535370610000],
[27, 1535370620000],
[29.05, 1535370630000],
[30.55, 1535370640000],
[27.700000000000003, 1535370650000],
[28.1, 1535370660000],
[28, 1535370670000],
[25.700000000000003, 1535370680000],
[25.05, 1535370690000],
[25.8, 1535370700000],
[26.9, 1535370710000],
[26.9, 1535370720000],
[29.9, 1535370730000],
[31.1, 1535370740000]
],
"target": "web_server_03"
},
{
"datapoints": [
[25.950000000000003, 1535370450000],
[26.6, 1535370460000],
[27.300000000000004, 1535370470000],
[28.25, 1535370480000],
[30.3, 1535370490000],
[31.200000000000003, 1535370500000],
[30.200000000000003, 1535370510000],
[28.5, 1535370520000],
[28.6, 1535370530000],
[29.450000000000003, 1535370540000],
[27.6, 1535370550000],
[27.4, 1535370560000],
[27.700000000000003, 1535370570000],
[28.75, 1535370580000],
[29.450000000000003, 1535370590000],
[28.200000000000003, 1535370600000],
[28.550000000000004, 1535370610000],
[27.150000000000002, 1535370620000],
[25.6, 1535370630000],
[27.450000000000003, 1535370640000],
[26.9, 1535370650000],
[26.05, 1535370660000],
[26.450000000000003, 1535370670000],
[25.75, 1535370680000],
[26.700000000000003, 1535370690000],
[28.35, 1535370700000],
[27.35, 1535370710000],
[26.25, 1535370720000],
[28.05, 1535370730000],
[30.950000000000003, 1535370740000]
],
"target": "web_server_04"
}
],
"spaceLength": 10,
"spyable": true,
"stack": true,
"steppedLine": false,
"targets": [],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"timezone": "browser",
"title": "server requests",
"tooltip": {
"msResolution": false,
"query_as_alias": true,
"shared": true,
"sort": 0,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": { "buckets": null, "mode": "time", "name": null, "show": true, "values": [] },
"yaxes": [
{ "format": "short", "logBase": 1, "max": null, "min": null, "show": true },
{ "format": "short", "logBase": 1, "max": null, "min": null, "show": true }
],
"yaxis": { "align": false, "alignLevel": null },
"zerofill": true,
"links": []
}
],
"refresh": false,
"schemaVersion": 16,
"snapshot": { "timestamp": "2018-08-27T11:52:22.450Z" },
"style": "dark",
"tags": ["demo"],
"templating": { "list": [] },
"time": {
"from": "2018-08-27T11:47:26.458Z",
"to": "2018-08-27T11:52:26.459Z",
"raw": { "from": "now-5m", "to": "now" }
},
"timepicker": {
"collapse": false,
"enable": true,
"notice": false,
"now": true,
"refresh_intervals": ["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"],
"status": "Stable",
"time_options": ["5m", "15m", "1h", "2h", " 6h", "12h", "24h", "2d", "7d", "30d"],
"type": "timepicker"
},
"timezone": "browser",
"title": "Big Dashboard",
"uid": "000000003",
"version": 16
},
"deleteKey": "<delete key>",
"expires": 0,
"external":true,
"key": "<access key>",
"name": "Big Dashboard"
}
Response body
{
"deleteKey": "<delete key>",
"deleteUrl": "https://play.grafana.org/api/snapshots-delete/<delete key>",
"key": "<access key>",
"url": "https://play.grafana.org/dashboard/snapshot/<access key>"
}
For you to be able to create an external snapshot using the HTTP API you’ll need to do at least step 3) using url of your Grafana snapshot server. The tricky part is how you’re going to generate the snapshotData - You basically needs to extract all queries in dashboard and for each use the datasource proxy call api. It’s possible, but not at all trivial.
We hope that Grafana in the future could have http api for generating snapshot and automatically fetching the data needed.