Need to have script to export data from Grafana dashboard to csv file. Input: (dashboard slug/name and time frame like: -1h or -24h) any link to grafana api/doc should be fine.
Well, 3yr old question, but I've actually done a whole bunch of exactly this to yield some reporting on dashboards in our grafana. You can use whatever you want (including bash to pull dashboard data out based on the UID and you can certainly search for the slugs, but the API pulls out all of its information in JSON like below:
DASH:
{
"dashboard": {
"id": 1,
"uid": "cIBgcSjkk",
"title": "Production Overview",
"tags": [
"templated"
],
"timezone": "browser",
"schemaVersion": 16,
"version": 0
},
"meta": {
"isStarred": false,
"url": "/d/cIBgcSjkk/production-overview"
}
}
This code can then be piped through jq
for your reporting. You can pull any variable through simplistic pathing of the dashboard json with option to use loops and lots of other features.
JQ:
$ curl -s https://grafana.local/api/dashboards/uid/cIBgcSjkk \
| jq -r '.dashboard |[ .uid, .title, .version ]| @csv'
"cIBgcSjkk","Production Overview",0
Refs:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With