dashboards as cfg: move dash/ds config files to /provisioning/*

This commit is contained in:
bergquist 2017-12-07 15:14:57 +01:00
parent 50bc801f1c
commit 2e610cb256
15 changed files with 97 additions and 54 deletions

View File

@ -20,11 +20,8 @@ logs = data/log
# Directory where grafana will automatically scan and look for plugins # Directory where grafana will automatically scan and look for plugins
plugins = data/plugins plugins = data/plugins
# Config files containing datasources that will be configured at startup # folder that contains provisioning config files that grafana will apply on startup and while running.
datasources = conf/datasources provisioning = conf/provisioning
# Config files containing folders to read dashboards from and insert into the database.
dashboards = conf/dashboards
#################################### Server ############################## #################################### Server ##############################
[server] [server]

View File

@ -0,0 +1,6 @@
- name: 'default'
org_id: 1
folder: ''
type: file
options:
folder: /var/lib/grafana/dashboards

View File

@ -0,0 +1,48 @@
# list of datasources that should be deleted from the database
delete_datasources:
- name: Graphite
org_id: 1
# list of datasources to insert/update depending
# whats available in the datbase
datasources:
# <string, required> name of the datasource. Required
- name: Graphite
# <string, required> datasource type. Required
type: graphite
# <string, required> access mode. direct or proxy. Required
access: proxy
# <int> org id. will default to org_id 1 if not specified
org_id: 1
# <string> url
url: http://localhost:8080
# <string> database password, if used
password:
# <string> database user, if used
user:
# <string> database name, if used
database:
# <bool> enable/disable basic auth
basic_auth:
# <string> basic auth username
basic_auth_user:
# <string> basic auth password
basic_auth_password:
# <bool> enable/disable with credentials headers
with_credentials:
# <bool> mark as default datasource. Max one per org
is_default:
# <map> fields that will be converted to json and stored in json_data
json_data:
graphiteVersion: "1.1"
tlsAuth: true
tlsAuthWithCACert: true
# <string> json object of data that will be encrypted.
secure_json_data:
tlsCACert: "..."
tlsClientCert: "..."
tlsClientKey: "..."
version: 1
# <bool> allow users to edit datasources from the UI.
editable: false

View File

@ -31,10 +31,10 @@ case "$1" in
cp /usr/share/grafana/conf/ldap.toml /etc/grafana/ldap.toml cp /usr/share/grafana/conf/ldap.toml /etc/grafana/ldap.toml
fi fi
if [ ! -f $DATASOURCES_CFG_DIR ]; then if [ ! -f $PROVISIONING_CFG_DIR ]; then
mkdir -p /etc/grafana/dashboards /etc/grafana/datasources mkdir -p $PROVISIONING_CFG_DIR/dashboards $PROVISIONING_CFG_DIR/datasources
cp /usr/share/grafana/conf/dashboards/sample.yaml $DASHBOARDS_CFG_DIR/sample.yaml cp /usr/share/grafana/conf/provisioning/dashboards/sample.yaml $PROVISIONING_CFG_DIR/dashboards/sample.yaml
cp /usr/share/grafana/conf/datasources/sample.yaml $DATASOURCES_CFG_DIR/sample.yaml cp /usr/share/grafana/conf/provisioning/datasources/sample.yaml $PROVISIONING_CFG_DIR/datasources/sample.yaml
fi fi
# configuration files should not be modifiable by grafana user, as this can be a security issue # configuration files should not be modifiable by grafana user, as this can be a security issue

View File

@ -18,9 +18,7 @@ RESTART_ON_UPGRADE=true
PLUGINS_DIR=/var/lib/grafana/plugins PLUGINS_DIR=/var/lib/grafana/plugins
DATASOURCES_CFG_DIR=/etc/grafana/datasources PROVISIONING_CFG_DIR=/etc/grafana/provisioning
DASHBOARDS_CFG_DIR=/etc/grafana/dashboards
# Only used on systemd systems # Only used on systemd systems
PID_FILE_DIR=/var/run/grafana PID_FILE_DIR=/var/run/grafana

View File

@ -33,8 +33,7 @@ DATA_DIR=/var/lib/grafana
PLUGINS_DIR=/var/lib/grafana/plugins PLUGINS_DIR=/var/lib/grafana/plugins
LOG_DIR=/var/log/grafana LOG_DIR=/var/log/grafana
CONF_FILE=$CONF_DIR/grafana.ini CONF_FILE=$CONF_DIR/grafana.ini
DATASOURCES_CFG_DIR=$CONF_DIR/datasources PROVISIONING_CFG_DIR=$CONF_DIR/provisioning
DASHBOARDS_CFG_DIR=$CONF_DIR/dashboards
MAX_OPEN_FILES=10000 MAX_OPEN_FILES=10000
PID_FILE=/var/run/$NAME.pid PID_FILE=/var/run/$NAME.pid
DAEMON=/usr/sbin/$NAME DAEMON=/usr/sbin/$NAME
@ -57,7 +56,7 @@ if [ -f "$DEFAULT" ]; then
. "$DEFAULT" . "$DEFAULT"
fi fi
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.datasources=$DATASOURCES_CFG_DIR cfg:default.paths.dashboards=$DASHBOARDS_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}" DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.provisioning=$PROVISIONING_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}"
function checkUser() { function checkUser() {
if [ `id -u` -ne 0 ]; then if [ `id -u` -ne 0 ]; then

View File

@ -14,14 +14,13 @@ Restart=on-failure
WorkingDirectory=/usr/share/grafana WorkingDirectory=/usr/share/grafana
RuntimeDirectory=grafana RuntimeDirectory=grafana
RuntimeDirectoryMode=0750 RuntimeDirectoryMode=0750
ExecStart=/usr/sbin/grafana-server \ ExecStart=/usr/sbin/grafana-server \
--config=${CONF_FILE} \ --config=${CONF_FILE} \
--pidfile=${PID_FILE_DIR}/grafana-server.pid \ --pidfile=${PID_FILE_DIR}/grafana-server.pid \
cfg:default.paths.logs=${LOG_DIR} \ cfg:default.paths.logs=${LOG_DIR} \
cfg:default.paths.data=${DATA_DIR} \ cfg:default.paths.data=${DATA_DIR} \
cfg:default.paths.plugins=${PLUGINS_DIR} \ cfg:default.paths.plugins=${PLUGINS_DIR} \
cfg:default.paths.datasources=${DATASOURCES_CFG_DIR} \ cfg:default.paths.provisioning=${PROVISIONING_CFG_DIR}
cfg:default.paths.dashboards=${DASHBOARDS_CFG_DIR}
LimitNOFILE=10000 LimitNOFILE=10000

View File

@ -45,10 +45,10 @@ if [ $1 -eq 1 ] ; then
cp /usr/share/grafana/conf/ldap.toml /etc/grafana/ldap.toml cp /usr/share/grafana/conf/ldap.toml /etc/grafana/ldap.toml
fi fi
if [ ! -f $DATASOURCES_CFG_DIR ]; then if [ ! -f $PROVISIONING_CFG_DIR ]; then
mkdir -p /etc/grafana/dashboards /etc/grafana/datasources mkdir -p $PROVISIONING_CFG_DIR/dashboards $PROVISIONING_CFG_DIR/datasources
cp /usr/share/grafana/conf/dashboards/sample.yaml $DASHBOARDS_CFG_DIR/sample.yaml cp /usr/share/grafana/conf/provisioning/dashboards/sample.yaml $PROVISIONING_CFG_DIR/dashboards/sample.yaml
cp /usr/share/grafana/conf/datasources/sample.yaml $DATASOURCES_CFG_DIR/sample.yaml cp /usr/share/grafana/conf/provisioning/datasources/sample.yaml $PROVISIONING_CFG_DIR/datasources/sample.yaml
fi fi
# Set user permissions on /var/log/grafana, /var/lib/grafana # Set user permissions on /var/log/grafana, /var/lib/grafana

View File

@ -32,8 +32,7 @@ DATA_DIR=/var/lib/grafana
PLUGINS_DIR=/var/lib/grafana/plugins PLUGINS_DIR=/var/lib/grafana/plugins
LOG_DIR=/var/log/grafana LOG_DIR=/var/log/grafana
CONF_FILE=$CONF_DIR/grafana.ini CONF_FILE=$CONF_DIR/grafana.ini
DATASOURCES_CFG_DIR=$CONF_DIR/datasources PROVISIONING_CFG_DIR=$CONF_DIR/provisioning
DASHBOARDS_CFG_DIR=$CONF_DIR/dashboards
MAX_OPEN_FILES=10000 MAX_OPEN_FILES=10000
PID_FILE=/var/run/$NAME.pid PID_FILE=/var/run/$NAME.pid
DAEMON=/usr/sbin/$NAME DAEMON=/usr/sbin/$NAME
@ -61,7 +60,7 @@ fi
# overwrite settings from default file # overwrite settings from default file
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME [ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.datasources=$DATASOURCES_CFG_DIR cfg:default.paths.dashboards=$DASHBOARDS_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}" DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.provisioning=$PROVISIONING_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}"
function isRunning() { function isRunning() {
status -p $PID_FILE $NAME > /dev/null 2>&1 status -p $PID_FILE $NAME > /dev/null 2>&1

View File

@ -18,9 +18,7 @@ RESTART_ON_UPGRADE=true
PLUGINS_DIR=/var/lib/grafana/plugins PLUGINS_DIR=/var/lib/grafana/plugins
DATASOURCES_CFG_DIR=/etc/grafana/datasources PROVISIONING_CFG_DIR=/etc/grafana/provisioning
DASHBOARDS_CFG_DIR=/etc/grafana/dashboards
# Only used on systemd systems # Only used on systemd systems
PID_FILE_DIR=/var/run/grafana PID_FILE_DIR=/var/run/grafana

View File

@ -14,14 +14,13 @@ Restart=on-failure
WorkingDirectory=/usr/share/grafana WorkingDirectory=/usr/share/grafana
RuntimeDirectory=grafana RuntimeDirectory=grafana
RuntimeDirectoryMode=0750 RuntimeDirectoryMode=0750
ExecStart=/usr/sbin/grafana-server \ ExecStart=/usr/sbin/grafana-server \
--config=${CONF_FILE} \ --config=${CONF_FILE} \
--pidfile=${PID_FILE_DIR}/grafana-server.pid \ --pidfile=${PID_FILE_DIR}/grafana-server.pid \
cfg:default.paths.logs=${LOG_DIR} \ cfg:default.paths.logs=${LOG_DIR} \
cfg:default.paths.data=${DATA_DIR} \ cfg:default.paths.data=${DATA_DIR} \
cfg:default.paths.plugins=${PLUGINS_DIR} \ cfg:default.paths.plugins=${PLUGINS_DIR} \
cfg:default.paths.datasources=${DATASOURCES_CFG_DIR} \ cfg:default.paths.provisioning=${PROVISIONING_CFG_DIR}
cfg:default.paths.dashboards=${DASHBOARDS_CFG_DIR}
LimitNOFILE=10000 LimitNOFILE=10000
TimeoutStopSec=20 TimeoutStopSec=20

View File

@ -2,6 +2,7 @@ package provisioning
import ( import (
"context" "context"
"path"
"path/filepath" "path/filepath"
"github.com/grafana/grafana/pkg/services/provisioning/dashboards" "github.com/grafana/grafana/pkg/services/provisioning/dashboards"
@ -10,12 +11,14 @@ import (
) )
func Init(ctx context.Context, homePath string, cfg *ini.File) error { func Init(ctx context.Context, homePath string, cfg *ini.File) error {
datasourcePath := makeAbsolute(cfg.Section("paths").Key("datasources").String(), homePath) provisioningPath := makeAbsolute(cfg.Section("paths").Key("provisioning").String(), homePath)
datasourcePath := path.Join(provisioningPath, "datasources")
if err := datasources.Provision(datasourcePath); err != nil { if err := datasources.Provision(datasourcePath); err != nil {
return err return err
} }
dashboardPath := makeAbsolute(cfg.Section("paths").Key("dashboards").String(), homePath) dashboardPath := path.Join(provisioningPath, "dashboards")
_, err := dashboards.Provision(ctx, dashboardPath) _, err := dashboards.Provision(ctx, dashboardPath)
if err != nil { if err != nil {
return err return err

View File

@ -50,13 +50,12 @@ var (
BuildStamp int64 BuildStamp int64
// Paths // Paths
LogsPath string LogsPath string
HomePath string HomePath string
DataPath string DataPath string
PluginsPath string PluginsPath string
DatasourcesPath string ProvisioningPath string
DashboardsPath string CustomInitPath = "conf/custom.ini"
CustomInitPath = "conf/custom.ini"
// Log settings. // Log settings.
LogModes []string LogModes []string
@ -475,9 +474,7 @@ func NewConfigContext(args *CommandLineArgs) error {
Env = Cfg.Section("").Key("app_mode").MustString("development") Env = Cfg.Section("").Key("app_mode").MustString("development")
InstanceName = Cfg.Section("").Key("instance_name").MustString("unknown_instance_name") InstanceName = Cfg.Section("").Key("instance_name").MustString("unknown_instance_name")
PluginsPath = makeAbsolute(Cfg.Section("paths").Key("plugins").String(), HomePath) PluginsPath = makeAbsolute(Cfg.Section("paths").Key("plugins").String(), HomePath)
DatasourcesPath = Cfg.Section("paths").Key("datasources").String() ProvisioningPath = makeAbsolute(Cfg.Section("paths").Key("provisioning").String(), HomePath)
DashboardsPath = Cfg.Section("paths").Key("dashboards").String()
server := Cfg.Section("server") server := Cfg.Section("server")
AppUrl, AppSubUrl = parseAppUrlAndSubUrl(server) AppUrl, AppSubUrl = parseAppUrlAndSubUrl(server)
@ -672,6 +669,6 @@ func LogConfigurationInfo() {
logger.Info("Path Data", "path", DataPath) logger.Info("Path Data", "path", DataPath)
logger.Info("Path Logs", "path", LogsPath) logger.Info("Path Logs", "path", LogsPath)
logger.Info("Path Plugins", "path", PluginsPath) logger.Info("Path Plugins", "path", PluginsPath)
logger.Info("Path Datasources", "path", DatasourcesPath) logger.Info("Path Provisioning", "path", ProvisioningPath)
logger.Info("App mode " + Env) logger.Info("App mode " + Env)
} }