Provision Grafana
Grafana has an active provisioning system that uses configuration files. This makes GitOps more natural since data sources and dashboards can be defined using files that can be version controlled.
Configuration file
Refer to Configuration for more information on what you can configure in grafana.ini
.
Configuration file locations
- Default configuration from
$WORKING_DIR/conf/defaults.ini
- Custom configuration from
$WORKING_DIR/conf/custom.ini
- The custom configuration file path can be overridden using the
--config
parameter
Note
If you have installed Grafana using the
deb
orrpm
packages, then your configuration file is located at/etc/grafana/grafana.ini
. This path is specified in the Grafanainit.d
script using the--config
file parameter.
Environment variables
You can use environment variable interpolation in all three provisioning configuration types.
The allowed syntax is either $ENV_VAR_NAME
or ${ENV_VAR_NAME}
, and it can be used only for values, not for keys or larger parts
of the configurations. If the environment variable value has a $
(e.g. Pa$sw0rd
), use the $ENV_VAR_NAME
syntax to avoid double expansion.
It’s not available in the dashboard’s definition files, just the dashboard provisioning
configuration.
Example:
datasources:
- name: Graphite
url: http://localhost:$PORT
user: $USER
secureJsonData:
password: $PASSWORD
You can use $$
if you have a literal $
in your value and want to avoid interpolation.
Configuration management tools
Currently, we don’t provide any scripts or manifests for configuring Grafana. Rather than spending time learning and creating scripts or manifests for each tool, we think our time is better spent making Grafana easier to provision. Therefore, we heavily rely on the expertise of the community.
Data sources
You can manage data sources in Grafana by adding YAML configuration files in the provisioning/datasources
directory.
Each configuration file can contain a list of datasources
to add or update during startup.
If the data source already exists, Grafana reconfigures it to match the provisioned configuration file.
The configuration file can also list data sources to automatically delete, called deleteDatasources
.
Grafana deletes the data sources listed in deleteDatasources
before adding or updating those in the datasources
list.
You can configure Grafana to automatically delete provisioned data sources when they’re removed from the provisioning file.
To do so, add prune: true
to the root of your data source provisioning file.
With this configuration, Grafana also removes the provisioned data sources if you remove the provisioning file entirely.
Running multiple Grafana instances
If you run multiple instances of Grafana, add a version number to each data source in the configuration and increase it when you update the configuration.
Grafana updates only data sources with the same or lower version number than specified in the configuration.
This prevents old configurations from overwriting newer ones if you have different versions of the datasource.yaml
file that don’t define version numbers, and then restart instances at the same time.
Example data source configuration file
This example provisions a Graphite data source:
For provisioning examples of specific data sources, refer to that data source’s documentation.
JSON data
Not all data sources have the same configuration settings. Only the most common fields are included in examples.
To provision the rest of a data source’s settings, include them as a JSON blob in the jsonData
field.
Common settings in the built-in core data sources include:
Note
Data sources tagged with HTTP* communicate using the HTTP protocol, which includes all core data source plugins except MySQL, PostgreSQL, and MSSQL.
For examples of specific data sources’ JSON data, refer to that data source’s documentation.
Secure JSON Data
Secure JSON data is a map of settings that are encrypted with a secret key from the Grafana configuration. The encryption hides content from the users of the application. This should be used for storing the TLS Cert and password that Grafana appends to the request on the server side. All of these settings are optional.
Note
The HTTP* tag denotes data sources that communicate using the HTTP protocol, including all core data source plugins except MySQL, PostgreSQL, and MS SQL.
Custom HTTP headers for data sources
Data sources managed with provisioning can be configured to add HTTP headers to all requests.
Configure the header name in the jsonData
field and the header value in secureJsonData
.
apiVersion: 1
datasources:
- name: Graphite
jsonData:
httpHeaderName1: 'HeaderName'
httpHeaderName2: 'Authorization'
secureJsonData:
httpHeaderValue1: 'HeaderValue'
httpHeaderValue2: 'Bearer XXXXXXXXX'
Plugins
You can manage plugin applications in Grafana by adding one or more YAML configuration files in the provisioning/plugins
directory.
Each configuration file can contain a list of apps
that update during start up.
Grafana updates each app to match the configuration file.
Note
This feature enables you to provision plugin configurations, not the plugins themselves. The plugins must already be installed on the Grafana instance.
Example plugin configuration file
Dashboards
You can manage dashboards in Grafana by adding one or more YAML configuration files in the provisioning/dashboards
directory.
Each configuration file can contain a list of dashboards providers
that load dashboards into Grafana from the local filesystem.
The dashboard provider configuration file looks somewhat like this:
When Grafana starts, it updates and inserts all dashboards available in the configured path. Then later on, Grafana polls that path every updateIntervalSeconds, looks for updated JSON files, and updates and inserts those into the database.
Note: Dashboards are provisioned to the root level if the
folder
option is missing or empty.
Making changes to a provisioned dashboard
While you can change a provisioned dashboard in the Grafana UI, those changes can’t be saved back to the provisioning source.
If allowUiUpdates
is set to true
and you make changes to a provisioned dashboard, you can Save
the dashboard, then changes persist to the Grafana database.
Note
If a provisioned dashboard is saved from the UI and then later updated from the source, the dashboard stored in the database will always be overwritten. The
version
property in the JSON file won’t affect this, even if it’s lower than the version of the existing dashboard.If a provisioned dashboard is saved from the UI and the source is removed, the dashboard stored in the database is deleted unless the configuration option
disableDeletion
is set totrue
.
If allowUiUpdates
is configured to false
, you are not able to make changes to a provisioned dashboard. When you click Save
, Grafana brings up a Cannot save provisioned dashboard dialog. The screenshot below illustrates this behavior.
Grafana offers options to export the JSON definition of a dashboard. Either Copy JSON to Clipboard
or Save JSON to file
can help you synchronize your dashboard changes back to the provisioning source.
Note
The JSON definition in the input field when using
Copy JSON to Clipboard
orSave JSON to file
has theid
field automatically removed to aid the provisioning workflow.
![](/static/img/docs/v51/provisioning_cannot_save_dashboard.png)
Reusable dashboard URLs
If the dashboard in the JSON file contains an UID, Grafana forces insert/update on that UID.
This allows you to migrate dashboards between Grafana instances and provisioning Grafana from configuration without breaking the URLs given because the new dashboard URL uses the UID as identifier.
When Grafana starts, it updates and inserts all dashboards available in the configured folders.
If you modify the file, then the dashboard is also updated.
By default, Grafana deletes dashboards in the database if the file is removed.
You can disable this behavior using the disableDeletion
setting.
Note
Provisioning allows you to overwrite existing dashboards which leads to problems if you reuse settings that are supposed to be unique. Be careful not to reuse the same
title
multiple times within a folder oruid
within the same installation as this causes weird behaviors.
Provision folders structure from filesystem to Grafana
If you already store your dashboards using folders in a git repo or on a filesystem, and also you want to have the same folder names in the Grafana menu, you can use foldersFromFilesStructure
option.
For example, to replicate these dashboards structure from the filesystem to Grafana,
/etc/dashboards
├── /server
│ ├── /common_dashboard.json
│ └── /network_dashboard.json
└── /application
├── /requests_dashboard.json
└── /resources_dashboard.json
You need to specify just this short provision configuration file.
apiVersion: 1
providers:
- name: dashboards
type: file
updateIntervalSeconds: 30
options:
path: /etc/dashboards
foldersFromFilesStructure: true
In this example, server
and application
become new folders in the Grafana menu.
Note
The
folder
andfolderUid
options should be empty or missing to makefoldersFromFilesStructure
work.To provision dashboards to the root level, store them in the root of your
path
.You can’t create nested folders structures, where you have folders within folders.
Alerting
For information on provisioning Grafana Alerting, refer to Provision Grafana Alerting resources.
Supported settings
The following sections detail the supported settings and secure settings for each alert notification type. Secure settings are stored encrypted in the database and you add them to secure_settings
in the YAML file instead of settings
.
Alert notification pushover
Alert notification discord
Alert notification slack
Alert notification victorops
Alert notification kafka
Alert notification LINE
Alert notification MQTT
TLS config
Alert notification pagerduty
Alert notification sensu
Alert notification sensugo
Alert notification prometheus-alertmanager
Alert notification teams
Alert notification dingding
Alert notification email
Alert notification hipchat
Alert notification opsgenie
Alert notification telegram
Alert notification threema
Alert notification webhook
TLS config
Alert notification googlechat
Alert notification Cisco Webex Teams
Grafana Enterprise
Grafana Enterprise supports: