Skip to main content

Using Grafana CLI

1. Managing Plugins

Command Description Options Notes
grafana-cli plugins list List all installed plugins -a to show all plugins including disabled Shows plugin ID, name, version, and status
grafana-cli plugins install <plugin-id> Install a plugin from Grafana.com --pluginVersion to specify version
--repo to specify repo URL
Installs the latest compatible version by default
grafana-cli plugins uninstall <plugin-id> Uninstall a plugin None Removes plugin files and updates plugin list
grafana-cli plugins update <plugin-id> Update a plugin to the latest version --pluginVersion to specify version Updates only if newer version is available
grafana-cli plugins enable <plugin-id> Enable a disabled plugin None Enables plugin for use in Grafana
grafana-cli plugins disable <plugin-id> Disable a plugin None Disables plugin but keeps files for re-enablement

Example: Install a specific plugin version

grafana-cli plugins install grafana-worldmap-panel --pluginVersion 0.3.1

Example: List all plugins including disabled ones

grafana-cli plugins list -a
Note: Plugin IDs can be found on the Grafana plugin page or using grafana-cli plugins list. Ensure the plugin is compatible with your Grafana version.

2. Resetting Admin Password

Command Description Notes
grafana-cli admin reset-admin-password Resets the admin password for the Grafana instance Requires Grafana server to be running

Example: Reset Admin Password

grafana-cli admin reset-admin-password --homepath /etc/grafana
Note: The command will prompt for a new password to be set. Ensure the new password meets security requirements.

3. Managing Users

Command Description Options
grafana-cli users create Create a new user --home-page-id, --org-id, --password, --role, --user
grafana-cli users update Update an existing user --home-page-id, --org-id, --password, --role, --user
grafana-cli users delete Delete a user --user
grafana-cli users list List all users --org-id

Example: Create a new user

grafana-cli users create --user john --password secret123 --email john@example.com --role Admin

Example: Update user role

grafana-cli users update --user john --role Editor
Note: The Grafana CLI requires the admin role to manage users.

4. Running Diagnostics

Command Description Options
grafana-cli diagnostics run Runs diagnostics to check the Grafana server status and configuration --output - Output format (json, text)

Example: Running diagnostics with JSON output

grafana-cli diagnostics run --output json
Note: Diagnostics can help identify configuration issues or performance bottlenecks in Grafana.
Warning: Running diagnostics may collect sensitive data. Review the output carefully before sharing.

5. Setting Config Overrides (--config flag)

Flag Description Example Value
--config Specifies the path to a configuration file or key-value pairs to override default settings. --config="app_url=http://localhost:3000"

Example: Override app URL using --config

grafana-server --config="app_url=http://localhost:3000"
Note: The --config flag can be used multiple times to set different configuration options.

6. Managing Data Sources

Command Description Options
grafana-cli datasources list List all data sources None
grafana-cli datasources add <datasource-type> Add a new data source --name, --url, --access, --basic-auth
grafana-cli datasources delete <datasource-name> Delete a data source None
grafana-cli datasources update <datasource-name> Update an existing data source --url, --access, --basic-auth

Example: Add a new Prometheus data source

grafana-cli datasources add prometheus --name "Prometheus" --url "http://localhost:9090" --access "proxy"

Example: List all data sources

grafana-cli datasources list
Note: Ensure the Grafana server has network access to the data source URL.

7. Migrating Data

Note: Grafana CLI data migration is typically used when upgrading Grafana versions or moving configurations between environments.
Migration Type Description Command Notes
Dashboard Migration Migrates dashboard JSON files to a newer Grafana version format. grafana-cli dashboards migrate Requires --from and --to version flags.
DataSource Migration Updates data source configurations to match new Grafana versions. grafana-cli datasources migrate Supports migration of json and yaml formats.
Plugin Migration Handles plugin compatibility and updates during Grafana upgrades. grafana-cli plugins migrate May require manual plugin reinstallation.

Example: Migrating Dashboards

grafana-cli dashboards migrate --from 8.0.0 --to 9.0.0 --path /var/lib/grafana/dashboards

Example: Migrating Data Sources

grafana-cli datasources migrate --from 8.0.0 --to 9.0.0 --path /var/lib/grafana/datasources

Migration Steps Overview

  • Backup current configuration and data sources.
  • Run grafana-cli dashboards migrate with appropriate version flags.
  • Run grafana-cli datasources migrate to update data sources.
  • Verify dashboard and data source compatibility in the new Grafana version.

8. Using Debug Mode

Option Values Description
--debug true Enables debug logging in Grafana CLI
--log.level debug Sets the logging level to debug for more verbose output

Example: Enable Debug Mode

grafana-cli --debug plugins list
Note: Debug mode increases log verbosity and can impact performance. Use only when troubleshooting.

9. Running Database Commands

Command Description Options Notes
grafana-cli db migrate Run database migrations -config, -homepath Ensures database schema is up to date
grafana-cli db status Check database migration status -config, -homepath Shows current migration version
grafana-cli db rollback Rollback database to a previous version -config, -homepath, -version Use with caution, may cause data loss

Example: Running database migrations

grafana-cli db migrate -config /etc/grafana/grafana.ini

Example: Checking database status

grafana-cli db status -homepath /var/lib/grafana

10. Viewing Grafana Version (--version)

Command Description Example
grafana-cli --version Displays the installed version of Grafana CLI grafana-cli --version

Example: Check Grafana CLI version

$ grafana-cli --version
Grafana CLI version 1.2.3

Was this article helpful?