2022-05-26 10:06:25 -05:00
---
aliases:
2022-12-09 10:36:04 -06:00
- administration/cli/
2023-04-26 13:18:03 -05:00
description: Guide to using grafana cli
2022-05-26 10:06:25 -05:00
keywords:
- grafana
- cli
2023-04-26 13:18:03 -05:00
- grafana cli
2022-05-26 10:06:25 -05:00
- command line interface
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 03:10:12 -05:00
labels:
products:
- enterprise
- oss
2022-05-26 10:06:25 -05:00
title: Grafana CLI
weight: 400
---
2016-12-12 06:15:35 -06:00
# Grafana CLI
2021-02-22 18:56:12 -06:00
Grafana CLI is a small executable that is bundled with Grafana server. It can be executed on the same machine Grafana server is running on. Grafana CLI has `plugins` and `admin` commands, as well as global options.
2016-12-12 06:15:35 -06:00
2020-01-10 11:41:39 -06:00
To list all commands and options:
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```
2023-04-26 13:18:03 -05:00
grafana cli -h
2020-01-10 11:41:39 -06:00
```
2021-08-06 08:52:36 -05:00
2021-02-22 18:56:12 -06:00
## Invoking Grafana CLI
2020-01-10 11:41:39 -06:00
2023-04-26 13:18:03 -05:00
To invoke Grafana CLI, add the path to the grafana binaries in your `PATH` environment variable. Alternately, if your current directory is the `bin` directory, use `./grafana cli` . Otherwise, you can specify full path to the CLI. For example, on Linux `/usr/share/grafana/bin/grafana` and on Windows `C:\Program Files\GrafanaLabs\grafana\bin\grafana.exe` , and invoke it with `grafana cli` .
2020-01-10 11:41:39 -06:00
2023-05-22 15:45:28 -05:00
{{% admonition type="note" %}}
Some commands, such as installing or removing plugins, require `sudo` on Linux. If you are on Windows, run Windows PowerShell as Administrator.
{{% /admonition %}}
2020-01-10 11:41:39 -06:00
## Grafana CLI command syntax
The general syntax for commands in Grafana CLI is:
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli [global options] command [command options] [arguments...]
2020-01-10 11:41:39 -06:00
```
## Global options
Grafana CLI allows you to temporarily override certain Grafana default settings. Except for `--help` and `--version` , most global options are only used by developers.
Each global option applies only to the command in which it is used. For example, `--pluginsDir value` does not permanently change where Grafana saves plugins. It only changes it for command in which you apply the option.
### Display Grafana CLI help
`--help` or `-h` displays the help, including default paths and Docker configuration information.
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli -h
2020-01-10 11:41:39 -06:00
```
### Display Grafana CLI version
`--version` or `-v` prints the version of Grafana CLI currently running.
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli -v
2020-01-10 11:41:39 -06:00
```
### Override default plugin directory
`--pluginsDir value` overrides the path to where your local Grafana instance stores plugins. Use this option if you want to install, update, or remove a plugin somewhere other than the default directory ("/var/lib/grafana/plugins") [$GF_PLUGIN_DIR].
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --pluginsDir "/var/lib/grafana/devplugins" plugins install < plugin-id >
2020-01-10 11:41:39 -06:00
```
### Override default plugin repo URL
`--repo value` allows you to download and install or update plugins from a repository other than the default Grafana repo.
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --repo "https://example.com/plugins" plugins install < plugin-id >
2020-01-10 11:41:39 -06:00
```
### Override default plugin .zip URL
`--pluginUrl value` allows you to download a .zip file containing a plugin from a local URL instead of downloading it from the default Grafana source.
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --pluginUrl https://company.com/grafana/plugins/< plugin-id > -< plugin-version > .zip plugins install < plugin-id >
2020-01-10 11:41:39 -06:00
```
### Override Transport Layer Security
**Warning:** Turning off TLS is a significant security risk. We do not recommend using this option.
`--insecure` allows you to turn off Transport Layer Security (TLS) verification (insecure). You might want to do this if you are downloading a plugin from a non-default source.
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --insecure --pluginUrl https://company.com/grafana/plugins/< plugin-id > -< plugin-version > .zip plugins install < plugin-id >
2020-01-10 11:41:39 -06:00
```
### Enable debug logging
2020-05-18 03:23:12 -05:00
`--debug` or `-d` enables debug logging. Debug output is returned and shown in the terminal.
2020-01-10 11:41:39 -06:00
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --debug plugins install < plugin-id >
2020-01-10 11:41:39 -06:00
```
2020-05-18 03:23:12 -05:00
### Override a configuration setting
2016-12-12 06:15:35 -06:00
2020-01-10 11:41:39 -06:00
`--configOverrides` is a command line argument that acts like an environmental variable override.
2016-12-12 06:15:35 -06:00
2020-11-03 05:09:49 -06:00
For example, you can use it to redirect logging to another file (maybe to log plugin installations in Grafana Cloud) or when resetting the admin password and you have non-default values for some important configuration value (like where the database is located).
2016-12-12 06:15:35 -06:00
2020-01-10 11:41:39 -06:00
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --configOverrides cfg:default.paths.log=/dev/null plugins install < plugin-id >
2020-01-10 11:41:39 -06:00
```
2020-05-18 03:23:12 -05:00
### Override homepath value
2020-01-10 11:41:39 -06:00
Sets the path for the Grafana install/home path, defaults to working directory. You do not need to use this if you are in the Grafana installation directory when using the CLI.
2020-05-18 03:23:12 -05:00
2020-01-10 11:41:39 -06:00
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --homepath "/usr/share/grafana" admin reset-admin-password < new password >
2020-01-10 11:41:39 -06:00
```
2020-05-18 03:23:12 -05:00
### Override config file
2020-01-10 11:41:39 -06:00
2022-06-17 17:03:26 -05:00
`--config value` overrides the default location where Grafana expects the configuration file. Refer to [Configuration ]({{< relref "./setup-grafana/configure-grafana/" >}} ) for more information about configuring Grafana and default configuration file locations.
2020-01-10 11:41:39 -06:00
**Example:**
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli --config "/etc/configuration/" admin reset-admin-password mynewpassword
2020-01-10 11:41:39 -06:00
```
## Plugins commands
2022-06-17 17:03:26 -05:00
Grafana CLI allows you to install, upgrade, and manage your Grafana plugins. For more information about installing plugins, refer to [plugins page ]({{< relref "./administration/plugin-management/" >}} ).
2020-01-10 11:41:39 -06:00
All listed commands apply to the Grafana default repositories and directories. You can override the defaults with [Global Options ](#global-options ).
### List available plugins
```bash
2023-04-26 13:18:03 -05:00
grafana cli plugins list-remote
2020-01-10 11:41:39 -06:00
```
### Install the latest version of a plugin
```bash
2023-04-26 13:18:03 -05:00
grafana cli plugins install < plugin-id >
2020-01-10 11:41:39 -06:00
```
### Install a specific version of a plugin
```bash
2023-04-26 13:18:03 -05:00
grafana cli plugins install < plugin-id > < version >
2020-01-10 11:41:39 -06:00
```
### List installed plugins
```bash
2023-04-26 13:18:03 -05:00
grafana cli plugins ls
2020-01-10 11:41:39 -06:00
```
### Update all installed plugins
2021-08-06 08:52:36 -05:00
2020-01-10 11:41:39 -06:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli plugins update-all
2020-01-10 11:41:39 -06:00
```
### Update one plugin
```bash
2023-04-26 13:18:03 -05:00
grafana cli plugins update < plugin-id >
2020-01-10 11:41:39 -06:00
```
### Remove one plugin
```bash
2023-04-26 13:18:03 -05:00
grafana cli plugins remove < plugin-id >
2020-01-10 11:41:39 -06:00
```
## Admin commands
Admin commands are only available in Grafana 4.1 and later.
### Show all admin commands
```bash
2023-04-26 13:18:03 -05:00
grafana cli admin
2020-01-10 11:41:39 -06:00
```
2016-12-12 06:15:35 -06:00
### Reset admin password
2023-04-26 13:18:03 -05:00
`grafana cli admin reset-admin-password <new password>` resets the password for the admin user using the CLI. You might need to do this if you lose the admin password.
2020-01-10 11:41:39 -06:00
If there are two flags being used to set the homepath and the config file path, then running the command returns this error:
2016-12-12 06:15:35 -06:00
2020-05-18 03:23:12 -05:00
> Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath
2017-04-20 06:26:36 -05:00
2020-01-10 11:41:39 -06:00
To correct this, use the `--homepath` global option to specify the Grafana default homepath for this command:
```bash
2023-04-26 13:18:03 -05:00
grafana cli --homepath "/usr/share/grafana" admin reset-admin-password < new password >
2020-01-10 11:41:39 -06:00
```
2017-04-20 06:26:36 -05:00
2020-01-10 11:41:39 -06:00
If you have not lost the admin password, we recommend that you change the user password either in the User Preferences or in the Server Admin > User tab.
2017-04-20 06:26:36 -05:00
2022-06-17 17:03:26 -05:00
If you need to set the password in a script, then you can use the [Grafana User API ]({{< relref "./developers/http_api/user/#change-password" >}} ).
2020-01-13 09:38:52 -06:00
2020-01-10 11:41:39 -06:00
### Migrate data and encrypt passwords
2017-04-20 06:26:36 -05:00
2020-01-10 11:41:39 -06:00
`data-migration` runs a script that migrates or cleans up data in your database.
2017-04-20 06:26:36 -05:00
2020-01-10 11:41:39 -06:00
`encrypt-datasource-passwords` migrates passwords from unsecured fields to secure_json_data field. Returns `ok` unless there is an error. Safe to execute multiple times.
2017-04-20 06:26:36 -05:00
2020-01-10 11:41:39 -06:00
**Example:**
2021-08-06 08:52:36 -05:00
2017-10-05 12:01:03 -05:00
```bash
2023-04-26 13:18:03 -05:00
grafana cli admin data-migration encrypt-datasource-passwords
2017-04-20 06:26:36 -05:00
```