Grafana panel JSON generator in golang
Grafana has HTTP API but it seems no APIs for panel operations at a glance.
My team has several AWS accounts and I'd like to create dashboards with CloudWatch datasource for every account. For example, such dashboards have same contents with some panels. The panels are same for each dashboard, but parameters (e.g: instance ID, account ID, metric name, etc) are different. It bothers us to create dashboards manually one by one for all accounts.
So I created a command in golang to generate panel JSON for CloudWatch.
With the command, you can generate a JSON object, copy it and put it into PanelJSON
which can be shown
by clicking a menu.
The command can generate as the below example. You can put it into PanelJSON
and save.
$ gen-grafana-panel-json -datasource cw-ds-1 -filters "instance-id,i-8e045ea1"
{
"aliasColors": {},
"bars": false,
"datasource": "cw-ds-1",
"fill": 1,
"id": 1484367777,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"hideEmpty": false,
"hideZero": false,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 8,
"stack": false,
"steppedLine": false,
"targets": [
{
"alias": "webapp",
"dimensions": {
"InstanceId": "i-8e045ea1"
},
"metricName": "CPUUtilization",
"namespace": "AWS/EC2",
"period": "",
"refId": "A0",
"region": "ap-northeast-1",
"statistics": [
"Average"
]
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "EC2 CPUUtilization",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"transparent": false,
"type": "graph",
"xaxis": {
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
}