Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexrudd/snapshot_grafana
CLI tool to take snapshots of grafana dashboards
https://github.com/alexrudd/snapshot_grafana
cli grafana prometheus
Last synced: about 1 month ago
JSON representation
CLI tool to take snapshots of grafana dashboards
- Host: GitHub
- URL: https://github.com/alexrudd/snapshot_grafana
- Owner: alexrudd
- License: mit
- Archived: true
- Created: 2017-02-01T17:36:10.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-14T14:20:50.000Z (over 6 years ago)
- Last Synced: 2024-09-25T23:43:27.436Z (about 1 month ago)
- Topics: cli, grafana, prometheus
- Language: Go
- Size: 355 KB
- Stars: 9
- Watchers: 6
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# snapshot_grafana
CLI tool to take snapshots of grafana dashboards
Currently supports only the Prometheus datasource.
# Warning
This tool is very much in development and is likely to change considerably.
# Todo
* ~~Refactor and break out into lib~~( The refactoring still needs to happen)
* ~~find out why timeshifted stuff doesn't work~~ (more of an issue with null "snapshotData" fields)
* ~~make it usable as a cli tool~~ (barely)
* ~~document~~ (some)
* ~~Dockerise~~ (alexrudd/snapshot_grafana)
* snapshot annotations
* async the datasource reqs
* "Take()" should take a context
* use a json library instead of all that casting
* support other datasources
* builds# Usage
## As Lib:
```go
package mainimport (
"fmt"
"github.com/alexrudd/snapshot_grafana/snapshot"
"net/url"
"time"
)func main() {
grafanaURL, _ := url.Parse("http://grafana.myorg.com/")
from := time.Date(2017, time.February, 05, 6, 0, 0, 0, time.Local)
to := time.Date(2017, time.February, 05, 12, 0, 0, 0, time.Local)config := &snapshot.Config{
// The domain and path where your Grafana instance is located
GrafanaAddr: grafanaURL,
// An api key which has admin privelages and access to the target dashboard
GrafanaAPIKey: "eyJrIjoib3M0RDRWNmxYbnQ3bEJKNVUwOFE1Rk0wZnFrRXR3eDEiLCJuIjoia2V5IiwiaWQiOjN9",
}
snapclient, _ := snapshot.NewSnapClient(config)takeConfig := &snapshot.TakeConfig{
DashSlug: "my-dash-slug",
From: &from,
To: &to,
}
snapshot, err := snapclient.Take(takeConfig)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(snapshot.URL)
}```
## As cli
```sh
go get github.com/alexrudd/snapshot_grafana
snapshot_grafana \
-grafana_addr="http://grafana.myorg.com/" \
-grafana_api_key="eyJrIjoib3M0RDRWNmxYbnQ3bEJKNVUwOFE1Rk0wZnFrRXR3eDEiLCJuIjoia2V5IiwiaWQiOjN9" \
-dashboard_slug="my-dash-slug"
```Or using Docker:
```sh
docker run --rm alexrudd/snapshot_grafana \
-grafana_addr="http://grafana.myorg.com/" \
-grafana_api_key="eyJrIjoib3M0RDRWNmxYbnQ3bEJKNVUwOFE1Rk0wZnFrRXR3eDEiLCJuIjoia2V5IiwiaWQiOjN9" \
-dashboard_slug="my-dash-slug"
```