grafana-toolbox / grafana-snapshots-tool

Python tool using Grafana API to generate fully autonomous snapshots that can be imported or exported as JSON files to external Grafana.
Apache License 2.0
13 stars 5 forks source link
grafana grafana-client grafana-snapshots grafana-utils

Grafana Snapshots Tool

A python3 bases application to build grafana snapshots that contains data(!) using Grafana API and a python interface grafana-client

The aim of this tool is to:

  1. Easily build snapshots from existing Grafana dashboard.
  2. Export the snapshots to a local storage in JSON format so it can be sent, imported an visualized to a remote Grafana.
  3. Import a snapshot in JSON format to a Grafana.

The development of this tool began when we discovered that there was no solution to automate the creation of snapshots from Grafana; only the functionality from the GUI was operational. That was a sticking point for us since it prevented us from being able to provide reports other than mannually build dashboards with statics screenshots. With this tool, we are able to build static dashboards, also called snapshots, that can be shared and visualized in grafana. It can be also used to store particular situation even if the data window is out of the scope of the retention of the datasource.

Install using this repo

pip install git+https://github.com/peekjef72/grafana-snapshots-tool.git

Install pypi package

install from pypi

pip3 install grafana-snapshots-tool 

Requirements:

Configuration

The configuration is stored in a YAML file.

It contains 3 parts:

Usages

build a directory structure:

usage:

grafana-snapshots -h
usage: grafana-snapshots [-h] [-b BASE_PATH] [-c CONFIG_FILE]
                         [-d DASHBOARD_NAME] [-F GRAFANA_FOLDER]
                         [-f TIME_FROM] [-g GRAFANA_LABEL] [-i IMPORT_FILE]
                         [-o CONTEXT_NAME] [-p] [-s SNAPSHOT_NAME]
                         [-t TIME_TO] [-v] [-V]
                         [ACTION]

then enter into your directory and type in you commands.

Example:

$ grafana-snapshots -d "My dashboard"
OK: new snapshot 'My_dashboard_202010241750.json' created.

then you can go into Grafana Gui and find the snapshot in dashboard/Manage/Snapshots part.

$ grafana-snapshots -d "My dashboard" -f "now-1d" export
OK: snapshot exported to './snapshots/My_dashboard_202010241750.json' exported.

then you can find the created file in the "snapshots" dir.

$ grafana-snapshots -f './snapshots/My_dashboard_202010241750.json' import
OK: snapshot './snapshots/My_dashboard_202010241750.json' imported.

then you can go into Grafana Gui and find the snapshot in dashboard/Manage/Snapshots part.

TODO - Known Limitations: