-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an API to import/export dashboards #273
Comments
I am guessing the only way to do this would be an import/export to/from elastic search since grafana has no server side components, it runs in the browser only. |
Yes, you are correct. Elasticsearch has a http API :) |
Since I am interested as well in doing this (probably a node.js script making REST calls to ES), is there something we should know as to where the endpoints are? I imagine it's just a matter of issuing a GET for the right dashboard to export and a PUT to import a new dashboard? I can't contribute (yet) to the AngularJS app but I might be able to help with some server side utilities |
elasticsearch has a pretty simple http api, look at the network tab in chrome dev tools to see the calls for GET and PUT for dashboards |
So to write (import), it seems you'd do a PUT to http://edasquemac1:9200/grafana-dash/dashboard/Dashboard name with a JSON payload of { dashboard: " -- JSON source for the dashboard ", group: "guest",tags: [], title: "Name of the Dashboard", user: "guest" } I'll try that. |
In the meantime I've worked a python script to backup the user generated dashboards, not sure what to do with it other than write a short post about it. |
Funny, I just submitted a pull request to do this in JS/Coffeescript: https://github.com/torkelo/grafana/pull/340 |
I think there is definitively the need to produce something "official" that helps people deploying Grafana with automating the backup of "user generated dashboards", in particular since there is no built in authentication at the moment, it's too easy to accidentally destroy another user dashboard. I'm thinking a page in the wiki cleaning up our discussion here and referencing whatever gets in the grafana repo. I pinged @torkelo on twitter about this too. My gist is a "watered" version of what I run in prod as I've added a push of the tarball to an S3 bucket via config file for AWS credentials+bucket, I'll be happy to clean it up and add the "backup to S3" feature if there is interest for it. |
It's similar to what I built though I do the Export & the Import and it's done in JS (well, coffeescript). Our workflow is that people commit dashboards to a directory in our gitana repo. A process takes those files and imports there directly. That way we keep a log of imports and the commits linked to them. I'll eventually remove the import button from grafana for our users so people can't get around the dashboard update/create mechanism. Users (developers, devops) build their dashboards on their local grafana instance, export the json through the tool (easy grunt task) then commit their changes to the repo. It can probably be refined by a competent devops but it works for us for now. |
That flow makes a lot of sense at least to me and is very simple to implement, so I'm definitively going to propose something largely inspired by it, many thanks for sharing. |
We finished implementing that flow here. We had to add clearing the dashboards and re-importing from fs on each commit to make things simpler. |
We sticked to automated backups only because we have "non git" business users of grafana, sure we could have asked them to save then export their dashboards but that was adding an extra step. |
The downside being that they can happily overwrite each other's changes.... |
Yes indeed one of the major ones, also backing up is not configuration management, I argued in favor of a git centric model, but then we would have had a need for a test instance to "develop" dashboards (no way I'd get business type of users to install grafana locally) and train people to git or have them open tickets with the dashboards JSON, either way extra steps vs automatically backed up to S3 every X min. It could be also improved just by being a push incremental backup instead of scheduled which would limit the overwriting issue. |
+1 for api to import graphs. it could be something like a python library that assists with creating the official json representation of a dashboard, so the input of the functions would be a graphite graph definition ( |
implemented in Grafana 2.0 |
Periodic collector refresh
There is no Http API import, I need to automatically generate the instrument panel by Http |
Here is a http api to create / update dashboarda |
where |
If I have a JSON I can directly generate the dashboard through the HTTP request. |
check the http api docs :) |
docs.grafana.org |
thanks |
I have running grafana installed from rpm (latest version, 3.1.0), but it seems it is ignoring config file /etc/grafana/grafana.ini. I have modified it to enable json dashboards like this:
Given directory contains some json and js files. Accessing generated (*.js) dashboards is working and simple (also without moddification of settings file). I just open http://localhost:3000/dashboard/script/dashboardgenerator.js?environment=test8 and it is working. But when I want to provision dashoard to be visible in menu of grafana (in upper left menu with list of dashboards), I do not know, where should I put my dashboards. I need to make possible to search through available dashboards and not only to guess what parameter should be passed to my javascript. Is it possible to somehow import dashboard and make it visible in dashboard list? (and by import I mean some programmatic way, not by playing in grafana web interface and importing things by hand) |
Hi LuboVarga, I just used
And as soon as I put a json dashboard in that folder, it appears on the dashboard list in Grafana. Perhaps try to have only .json in it and see what happens. |
Thanks @Djidiouf, it is working now. I am not sure, if I had wrong path (now it was wrong), or I have tried other than json suffixes. Just for the record, I have solved provisioning of dashboards from saltstack through provisioning json/request files, curl and by using http api:
Dashboards get saved into |
I solved the problem like this: curl --user admin:admin 'http://IPADDR:3000/api/datasources' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"test","type":"prometheus","url":"http://localhost:9090","access":"proxy","basicAuth":false}' 2-For adding the customized json dashboard, edit grafana.ini file and enable Dashboard json file section like below: 3- then copy dashboard json file to /var/lib/grafana/dashboards (you need to restart the service) |
In case anyone else struggles to get this happening a few years later, the options have moved to |
Unless I'm mistaken there is no programatic way to easily export/import user generated dashboards. Such API would be useful to pair with tooling (e.g. config management) so user generated dashboard are automatically managed.
The text was updated successfully, but these errors were encountered: