Manage Grafana
from the command line.
Full coverage of dashboards, datasources, folders, alerts, annotations, orgs, teams, users, and service accounts. Designed for both humans and AI coding agents, with first-class JSON output for scripts and pipelines.
01Install
Get the binary
Pick whichever fits your setup. The binary is grafana. The install script handles platform detection and PATH setup.
Recommended, install script
curl -sSfL https://raw.githubusercontent.com/piyush-gambhir/grafana-cli/main/install.sh | sh
Via Go
go install github.com/piyush-gambhir/grafana-cli@latest
Build from source
git clone https://github.com/piyush-gambhir/grafana-cli.git
cd grafana-cli
make install # or: go build -o grafana . && sudo mv grafana /usr/local/bin/
From releases
Download a prebuilt binary for your platform from the
releases page
and place it on your PATH.
02Quick start
Authenticate once, then operate
Add -o json to any command for machine-readable output.
# 1. Authenticate (saves a profile to ~/.config/grafana-cli/) grafana login # 2. List dashboards grafana dashboard list # 3. Search dashboards by title or tag grafana dashboard list -q "production" --tag monitoring # 4. Get a dashboard as JSON grafana dashboard get <uid> -o json # 5. List datasources grafana datasource list # 6. List firing alerts grafana alert list --state firing # 7. Add a deploy annotation grafana annotation create --text "Deployed v1.2.3" --tags deploy # 8. Pipe JSON output to jq grafana dashboard list -o json | jq '.[].title'
03Authentication
Three ways to connect
Token, basic auth, or saved profile. Precedence: CLI flags > environment variables > saved profile.
interactive loginDefault
Run grafana login, prompts for URL and token, saves a named profile.
service account tokenRecommended
Set GRAFANA_TOKEN + GRAFANA_URL. No interactive prompt needed.
basic authSelf-hosted
Set GRAFANA_USERNAME + GRAFANA_PASSWORD + optional GRAFANA_ORG_ID.
Service account token (CI / agents)
export GRAFANA_URL=https://grafana.example.com export GRAFANA_TOKEN=glsa_xxxxxxxxxxxx
Basic auth
export GRAFANA_URL=https://grafana.example.com export GRAFANA_USERNAME=admin export GRAFANA_PASSWORD=your-password export GRAFANA_ORG_ID=1
Multiple profiles
grafana login # saves as default grafana config use-profile prod # switch active profile grafana dashboard list --profile staging # one-off override
04Commands
Broad coverage of the Grafana API
Every group has its own --help. A selection of the top-level groups:
grafana dashboard
List, get, create, delete dashboards (alias:
dash, db)grafana datasource
Inspect and manage data sources
grafana folder
Organize dashboards into folders
grafana alert
View alert rules, instances, and silences
grafana annotation
Add deploy markers and event annotations to dashboards
grafana org
Manage organizations
grafana team
Manage teams and team members
grafana user
Manage users and current user
grafana service-account
Manage service accounts and their tokens
grafana config
View/set configuration, manage profiles
grafana login
Interactive authentication setup
grafana version · update
Print CLI version; self-update to the latest release
Output formats
grafana dashboard list # table (default) grafana dashboard list -o json # JSON grafana dashboard list -o yaml # YAML
Global flags
-o, --output
Output format: table, json, yaml
--profile
Configuration profile to use
--url
Grafana server URL
--token
API token or service account token
--username
Username for basic auth
--password
Password for basic auth
--org-id
Organization ID