gcli is a powerful Go-based command-line interface for interacting with the Grafana API. It allows you to manage multiple Grafana profiles, switch between organizations, and manage data sources with ease.
- Profile Management: Save multiple Grafana instances and switch between them.
- Organization (Tenant) Management: List, create, delete, update, and switch active organizations.
- Data Source Management: Full CRUD operations for data sources (List, Create, Read details, Update, Delete) with tabular output and interactive editing.
- Dashboard Management: List, read, create (handles external templates with mapping), update (interactive editor), and delete dashboards.
- Generic Requests: Make raw API calls to any Grafana endpoint.
Upcoming features and improvements:
- Folder Management: Full control over dashboard folders.
- User Management: Manage Grafana users via CLI.
- Group/Team Management: Manage teams and permissions.
- Improved Output Formats: More flexible output options (CSV, etc.).
- Go 1.20 or later
Clone the repository and run:
make installThis will generate the gcli binary, move it to /usr/local/bin, and set up auto-completion for your shell.
Manage your Grafana API profiles.
- Add a profile:
./gcli config add --name my-grafana --url https://grafana.example.com --user admin --pass secret
- List profiles:
./gcli config list
- Set active profile:
./gcli config use my-grafana
Manage organizations in the active Grafana profile.
- List organizations:
./gcli org list
- Select active organization:
./gcli org use "Main Org." - Create organization:
./gcli org create --name "New Org" - Delete organization:
./gcli org rm 12
- Update organization:
./gcli org update 12 --name "New Name"
Manage your Grafana dashboards.
- List dashboards:
./gcli dash list
- Read dashboard (extracts
.dashboardfield):./gcli dash read <uid>
- Export for sharing (external template):
./gcli dash read <uid> --external
- Create dashboard (handles external templates with datasource mapping):
./gcli dash create --file dash.json
- Update dashboard (interactive editor with retry logic):
./gcli dash update <uid>
- Remove dashboard:
./gcli dash rm <uid>
Manage data sources in the active organization.
- List data sources (tabular view):
./gcli ds list
- List data sources (full JSON details):
./gcli ds list --details
- Read data source details:
./gcli ds read "Prometheus"
- Create data source (via flags):
./gcli ds create --name my-db --type graphite --url http://localhost:8080 --access proxy
- Create data source (via file):
./gcli ds create --file ds.json
- Update data source (interactive editor):
# Opens your default $EDITOR with the current config ./gcli ds update my-db - Update data source (via file):
./gcli ds update my-db --file update.json
- Remove data source:
./gcli ds rm my-db
Make any request to the active Grafana instance.
./gcli request GET /api/healthProfiles and active settings are stored in ~/.gcli/config.yaml.