grafana-import: Import and export Grafana dashboards

About

grafana-import is a program for elegantly importing and exporting Grafana dashboards using the Grafana HTTP API. It is based on grafana-client, and supports dashboard-as-code workflows.

Features

  • Export dashboards into JSON format.
  • Import dashboards into Grafana, both in native JSON format, or emitted by dashboard builders, supporting dashboard-as-code workflows.
    • Supported builders are Grafonnet, grafana-dashboard, grafanalib, and any other executable program which emits Grafana Dashboard JSON on STDOUT.
    • The import action preserves the version history of dashboards.
  • Watchdog: For a maximum of authoring and editing efficiency, the watchdog monitors the input dashboard for changes on disk, and re-uploads it to the Grafana API, when changed.
  • Remove dashboards.

Resources

Installation

pip install --upgrade 'grafana-import[builder] @ git+https://github.com/grafana-toolbox/grafana-import.git'

Synopsis

This procedure outlines an almost optimal dashboard-as-code workflow, with no JSON in sight, where the dashboard is defined by Python code, using grafana-dashboard. The input dashboard will be monitored for changes on disk, and re-uploaded to the Grafana API each time when changed.

# Prepare a dashboard.
wget https://github.com/grafana-toolbox/grafana-snippets/raw/main/dashboard/gd-prometheus.py
# Define the URL to your Grafana instance.
export GRAFANA_URL=http://admin:admin@localhost:3000
# Start the program in watchdog mode.
grafana-import import --overwrite --reload -i gd-prometheus.py

Of course, you can also use the program to upload dashboards in traditional Grafana Dashboard JSON format, with or without watchdog mode.

wget https://github.com/grafana-toolbox/grafana-snippets/raw/main/dashboard/native-play-influxdb.json
grafana-import import -i native-play-influxdb.json