This repository manages the "Infrastructure as Code" (IaC) configuration for PANOSETI's Grafana instance. It ensures that our dashboards and datasources are version-controlled, reproducible, and recoverable.
Grafana does not support "Two-Way Sync" natively. We use a "ClickOps to Git" workflow:
- Provision: Grafana launches and loads dashboards from the
dashboards/directory. - Edit: Users edit dashboards in the Grafana UI (enabled via
allowUiUpdates: true). - Sync: An administrator runs
sync_grafana.pyto pull UI changes back to the localdashboards/JSON files. - Commit: Changes are committed to Git.
The sync script requires Python 3 and a few libraries:
pip install requests python-slugify
To allow the script to talk to Grafana, you need a Service Account Token.
- Log in to Grafana (Admin).
- Go to Administration > Users and access > Service Accounts.
- Click Add service account.
- Name:
SyncBot - Role:
Viewer(Safe for pulling) orAdmin(If pushing is needed later).
- Click Add token -> Generate token.
- Copy the token (e.g.,
glsa_...).
This script compares the live Grafana dashboards with your local JSON files.
Basic Usage (Dry Run): By default, the script will not write to disk. It only shows you what changed.
export GRAFANA_API_KEY="glsa_YOUR_TOKEN_HERE"
python3 sync_grafana.py
Viewing Diffs: To see exactly which lines changed in the JSON:
python3 sync_grafana.py --diff
Saving Changes (The "Sync"): To actually overwrite your local files with the live versions:
python3 sync_grafana.py --sync
| Flag | Description |
|---|---|
--key <token> |
Service Account Token (Can also use GRAFANA_API_KEY env var) |
--url <url> |
Grafana URL (Default: http://localhost:3000) |
--dir <path> |
Output directory (Default: ./grafana_provisioning/dashboards) |
--sync |
Required to save. If omitted, runs in Read-Only mode. |
--diff |
Prints colored line-by-line diffs of changes. |
datasources/: YAML configurations for InfluxDB, Loki, etc.dashboards/: JSON models of the dashboards.sync_grafana.py: The bridge tool.Dockerfile: Builds the custom Grafana image with these files pre-loaded.