Configuring Grafana Server
1. Editing grafana.ini File
| Property | Default Value | Description |
|---|---|---|
| app_mode | production |
Set to development for development mode with more verbose logging. |
| domain | |
Domain name used for cookies and redirects. Set to your Grafana server's public URL. |
| root_url | %(protocol)s://%(domain)s:%(http_port)s |
Root URL for Grafana. Used in redirects and links. |
| http_port | 3000 |
HTTP port to listen on. |
| protocol | http |
Protocol to use for the server. Can be http or https. |
| cert_file | |
Path to the certificate file for HTTPS. |
| key_file | |
Path to the private key file for HTTPS. |
| enable_gzip | false |
Enable GZIP compression for responses. |
| static_root_path | public |
Path to the static assets directory. |
| serve_from_sub_path | false |
Set to true if Grafana is served from a sub-path. |
Example: Basic grafana.ini Configuration
[server]
http_port = 3000
domain = grafana.example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s
[security]
admin_user = admin
admin_password = secret123
Note: The
grafana.ini file is located in the Grafana configuration directory, typically /etc/grafana/grafana.ini on Linux systems.
2. Setting Server Options
| Option | Values | Description |
|---|---|---|
| server.http_port | 3000 |
HTTP port to listen on |
| server.domain | localhost |
Domain name for the server |
| server.root_url | %(protocol)s://%(domain)s:%(http_port)s/ |
Root URL for the server |
| server.serve_from_sub_path | false |
Serve Grafana from a sub-path |
| server.disable_sanitize_html | false |
Disable HTML sanitization (not recommended) |
Example: Setting server options in grafana.ini
[server]
http_port = 3001
domain = example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
disable_sanitize_html = false
3. Configuring Protocol
| Option | Values | Notes |
|---|---|---|
| protocol | http or https |
Specifies the protocol to use for the Grafana server |
| http_port | 3000 |
Port to listen on for HTTP requests (default: 3000) |
| https_port | 443 |
Port to listen on for HTTPS requests (default: 443) |
| http_addr | 0.0.0.0 |
Address to bind the HTTP server to (default: 0.0.0.0) |
| https_enabled | true or false |
Enable HTTPS support (default: false) |
| http_mode | production or development |
Set the server mode (default: production) |
Example: Configure Protocol Settings
[server]
protocol = https
http_port = 3001
https_port = 443
http_addr = 0.0.0.0
https_enabled = true
http_mode = production
4. Setting Up Environment Variables
| Variable Name | Default Value | Description | Notes |
|---|---|---|---|
| GF_SERVER_HTTP_PORT | 3000 |
HTTP port for the Grafana server | Can be overridden via command line or config file |
| GF_SERVER_ROOT_URL | %(protocol)s://%(domain)s:%(http_port)s |
Root URL for the Grafana server | Used for generating links in emails and notifications |
| GF_DATABASE_TYPE | sqlite3 |
Database type to use for Grafana | Supports mysql, postgres, and sqlite3 |
| GF_DATABASE_HOST | localhost:3306 |
Database host address and port | Required when GF_DATABASE_TYPE is not sqlite3 |
| GF_DATABASE_NAME | grafana |
Name of the database to use | Must exist before starting Grafana if using external DB |
| GF_DATABASE_USER | grafana |
Database user for authentication | Must have appropriate permissions to access the database |
| GF_DATABASE_PASSWORD | grafana |
Password for the database user | Should be set securely and not exposed in logs or config files |
| GF_SECURITY_ADMIN_USER | admin |
Admin username for Grafana | Can be changed after initial setup |
| GF_SECURITY_ADMIN_PASSWORD | admin |
Admin password for Grafana | Must be changed after initial setup for security reasons |
| GF_AUTH_ANONYMOUS_ENABLED | false |
Enable anonymous access to Grafana | Only for development or testing environments |
| GF_AUTH_ANONYMOUS_ORG_ROLE | Viewer |
Role assigned to anonymous users | Valid values: Viewer, Editor, Admin |
| GF_LOG_LEVEL | info |
Log level for Grafana server logs | Valid values: debug, info, warn, error |
| GF_LOG_MODE | console |
Log output mode | Valid values: console, file |
| GF_LOG_FILE_PATH | /var/log/grafana/grafana.log |
Path to the log file (if GF_LOG_MODE is file) |
Must be writable by the Grafana process |
Example: Setting Environment Variables in Docker
docker run -d \
--name=grafana \
-p 3000:3000 \
-e GF_SERVER_HTTP_PORT=3000 \
-e GF_DATABASE_TYPE=mysql \
-e GF_DATABASE_HOST=localhost:3306 \
-e GF_DATABASE_NAME=grafana \
-e GF_DATABASE_USER=grafana \
-e GF_DATABASE_PASSWORD=secret \
grafana/grafana-enterprise
Example: Setting Environment Variables in systemd Service File
[Service]
Type=simple
User=grafana
Group=grafana
Environment=GF_SERVER_HTTP_PORT=3000
Environment=GF_DATABASE_TYPE=sqlite3
Environment=GF_DATABASE_NAME=/var/lib/grafana/grafana.db
Environment=GF_SECURITY_ADMIN_USER=admin
Environment=GF_SECURITY_ADMIN_PASSWORD=admin
ExecStart=/usr/sbin/grafana-server
Restart=always
Note: Environment variables can be overridden by configuration file settings. If both are set, the configuration file takes precedence.
5. Configuring Paths
| Path Type | Default Location | Description |
|---|---|---|
| app_mode | production |
Sets the application mode. Options are production or development. |
| home_page | / |
Path to the home page. Can be used to redirect users to a specific dashboard. |
| static_root_path | public |
Directory where static assets (CSS, JS, images) are served from. |
| data_path | data |
Directory where Grafana stores data files like logs, plugins, and provisioning configs. |
| logs_path | data/logs |
Directory where Grafana logs are stored. |
| plugins_path | data/plugins |
Directory where Grafana plugins are installed. |
| provisioning_path | conf/provisioning |
Directory where Grafana looks for provisioning configuration files. |
| temp_data_lifetime | 24h |
How long temporary data files are kept before being deleted. |
Example: Setting Custom Paths in grafana.ini
[paths]
data = /custom/data/path
logs = /custom/logs/path
plugins = /custom/plugins/path
provisioning = /custom/provisioning/path
Note: Ensure that the directories specified in
grafana.ini exist and have appropriate permissions for Grafana to read and write.
6. Setting Timezone and Locale
| Configuration Option | Values | Description |
|---|---|---|
| app_mode | production, development |
Sets the application mode. Affects logging and error handling behavior. |
| default_app_mode | production, development |
Default app mode if not overridden by user. |
| timezone | UTC, Asia/Tokyo, America/New_York |
Default timezone for the Grafana server. Used for time-based queries and display. |
| locale | en-US, fr-FR, de-DE |
Default locale for the Grafana server. Affects date/time formatting and localization. |
Example: Setting Timezone and Locale in grafana.ini
[server]
timezone = America/New_York
locale = en-US
[app_mode]
default_app_mode = production
Note: Changes to timezone and locale require a Grafana server restart to take effect.
7. Configuring Logging
| Option | Values | Notes |
|---|---|---|
| log.level | debug, info, warn, error |
Set the minimum log level to output. Default is info. |
| log.mode | file, console, syslog |
Determines where logs are written. Default is console. |
| log.file.name | string |
Path to the log file when log.mode is set to file. |
| log.file.maxlines | integer |
Maximum number of lines in the log file before rotation. Default is 1000000. |
| log.file.maxsize | string |
Maximum size of the log file before rotation (e.g., 100m). Default is 100m. |
Example: Logging Configuration
[log]
level = debug
mode = file
file.name = /var/log/grafana/grafana.log
file.maxlines = 500000
file.maxsize = 50m
Note: Setting
log.level to debug can significantly impact performance in production environments.
8. Enabling Feature Toggles
Feature toggles in Grafana allow you to enable or disable experimental or preview features before they are officially released. These toggles can be managed via the Grafana configuration file or environment variables.
| Feature Toggle | Description | Default State | Configuration Method |
|---|---|---|---|
| feature_toggles | Enables or disables specific feature toggles. | Disabled | Configuration file or environment variable |
Note: Feature toggles are subject to change and may be removed in future versions. Always refer to the official Grafana documentation for the latest updates.
9. Setting Anonymous Access
| Setting | Description | Default | Notes |
|---|---|---|---|
| anonymous.enabled | Enables anonymous access to Grafana | false |
When enabled, users can access Grafana without logging in |
| anonymous.org.name | Organization name for anonymous users | Anonymous |
Visible to anonymous users in the UI |
| anonymous.org.role | Role assigned to anonymous users | Viewer |
Options: Viewer, Editor, Admin |
Example: Enable Anonymous Access
[anonymous]
enabled = true
org_name = "Anonymous"
org_role = "Viewer"
Note: Enabling anonymous access can pose security risks. Ensure that sensitive dashboards and data are protected by appropriate permissions.
10. Configuring SMTP Settings
| Option | Values | Notes |
|---|---|---|
| smtp.enabled | false |
Enable SMTP functionality |
| smtp.host | localhost:25 |
SMTP server host and port |
| smtp.user | |
SMTP username (optional) |
| smtp.password | |
SMTP password (optional) |
| smtp.skip_tls | false |
Disable TLS for SMTP connection |
| smtp.from_address | admin@grafana.com |
From address for emails |
| smtp.from_name | Grafana |
Name to display in "From" field |
Example: SMTP Configuration in grafana.ini
[smtp]
enabled = true
host = smtp.gmail.com:587
user = myemail@gmail.com
password = my_secure_password
skip_tls = false
from_address = admin@mycompany.com
from_name = Grafana Notifications
Note: Ensure that the SMTP server allows connections from your Grafana instance and that credentials are properly secured (e.g., via environment variables or encrypted config).