Giter Club home page Giter Club logo

grafana-migration-tool's Introduction

Grafana Migration Tool

Export and Import dashboards in Grafana are extremaly easy.

Unless you have to import 200 dashboards to the new Grafana instance. And the database must be switched from sqlite to MySQL. And some datasources are different. And source 200 dashboards are kept in ellegant directory structure which you want to migrate as well. And at the end it turns out that the migration must be started from the beginning.

To solve such migration problem the below migrating script is created. It is designed for helping with migration of Grafana dashboards from one instance to another (e.g. switching from builtin SQLite to MySQL etc).

Practically is possible to just migrate SQL scripts but it will not work for bigger instances, when the destination Grafana has already some dashboards or finally if datasources are defined differently. With this script is possible also to easily migrate/import only one Grafana directory, so can be served as Grafana Dashboard backup tool.

What does the script do ?

For standard migration we can run it in 3 phases:

  1. Export dashboards keeping directory information.
python grafana-migration.py --export

It saves Grafana folders definition into OUTPUT_DIRECTORY/grafana-folders.json and creates a local directory tree where it laters dumps each of the Dashboard into JSON file keeping name-convention we can see in Grafana UI.

  1. Import Grafana directory structure:
python grafana-migration.py --import_folders

It searches for OUTPUT_DIRECTORY/grafana-folders.json and tries to import the file into destination Grafana. Only directory structure is created in this step.

  1. Import Grafana dashboards per subdirectory
python grafana-migration.py --import_dashboards_from K8S
python grafana-migration.py --import_dashboards_from Cassandra

It connects to remote Grafana to get uid numbers of previosly imported folders and after that reads every file inside folder OUTPUT_DIRECTORY/K8S/*json modifies the Id to match existing folder and then imports. This must be repeated for each of the folders where we have exported dashboard json files.

  1. Delete folders hierarchy from Grafana
python grafana-migration.py --delete_folders

This must be used carefully - as it removes any existing folder with its dashboards. Only dashboards from General folder would survive this operation. Anyway it helps cleanup during testing of this migration.

Preparation

Create API keys for the source and destination Grafana instances. Then inside of the script there are 5 VARIABLES which must be defined:

GF_URL_SRC - source Grafana url where we import dashboards from

GF_KEY_SRC - API Key for this source Grafana

GF_URL_DST - destination Grafana url where we import dashboards and folders into. Also delete operation uses only this endpoint.

GF_KEY_DST - API Key for this destination Grafana

If deletion option is required then the last variable must be set: SURE_STRING

SURE_STRING = 'Yes I want delete all the dashboards' Otherwise scripts do nothing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.