mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Move monitor configuration from /etc/salt/minion to /etc/salt/monitor.
This commit is contained in:
parent
e9ce4383a6
commit
1b9248b1dd
4 changed files with 65 additions and 33 deletions
29
conf/minion
29
conf/minion
|
@ -117,32 +117,3 @@
|
|||
#
|
||||
# A dict for the test module:
|
||||
#test.baz: {spam: sausage, cheese: bread}
|
||||
|
||||
###### Monitor configuration #####
|
||||
###########################################
|
||||
# When the 'monitor' value is set salt will run the commands at the specified
|
||||
# interval or at the default interval.
|
||||
#
|
||||
#monitor.default_interval:
|
||||
# second: 10
|
||||
#
|
||||
#monitor:
|
||||
# - id: low-disk
|
||||
# run: status.diskusage / /var
|
||||
# every:
|
||||
# minute: 0
|
||||
# second: 10
|
||||
# foreach mntpt, usage:
|
||||
# - if ${usage.available} * 100 / ${usage.total} < 90:
|
||||
# - test.echo 'free disk space running low on $mntpt, ${usage.available/2.0**30} GB free'
|
||||
#
|
||||
# - id: high-load
|
||||
# run: status.loadavg
|
||||
# every:
|
||||
# minute: 0
|
||||
# second: 30
|
||||
# foreach interval, loadavg:
|
||||
# - if interval == '10-min' and loadavg > 20:
|
||||
# - test.echo 'WARNING 10 minute load average is $loadavg'
|
||||
# - elif interval == '10-min' and loadavg > 10:
|
||||
# - test.echo 'NOTICE 10 minute load average is $loadavg'
|
||||
|
|
37
conf/monitor
37
conf/monitor
|
@ -0,0 +1,37 @@
|
|||
# This configuration file is used by salt-monitor and is "overlaid" on the
|
||||
# configuration in /etc/salt/minion.
|
||||
|
||||
###### Logging settings #####
|
||||
###########################################
|
||||
# The location of the monitor log file
|
||||
#log_file: /var/log/salt/monitor
|
||||
|
||||
|
||||
###### Monitor configuration #####
|
||||
###########################################
|
||||
# When the 'monitor' value is set salt will run the commands at the specified
|
||||
# interval or at the default interval.
|
||||
#
|
||||
#monitor.default_interval:
|
||||
# second: 10
|
||||
#
|
||||
#monitor:
|
||||
# - id: low-disk
|
||||
# run: status.diskusage / /var
|
||||
# every:
|
||||
# minute: 0
|
||||
# second: 10
|
||||
# foreach mntpt, usage:
|
||||
# - if ${usage.available} * 100 / ${usage.total} < 90:
|
||||
# - test.echo 'free disk space running low on $mntpt, ${usage.available/2.0**30} GB free'
|
||||
#
|
||||
# - id: high-load
|
||||
# run: status.loadavg
|
||||
# every:
|
||||
# minute: 0
|
||||
# second: 30
|
||||
# foreach interval, loadavg:
|
||||
# - if interval == '10-min' and loadavg > 20:
|
||||
# - test.echo 'WARNING 10 minute load average is $loadavg'
|
||||
# - elif interval == '10-min' and loadavg > 10:
|
||||
# - test.echo 'NOTICE 10 minute load average is $loadavg'
|
|
@ -161,7 +161,7 @@ class Monitor(object):
|
|||
'''
|
||||
def __init__(self):
|
||||
self.cli = self.__parse_cli()
|
||||
self.opts = salt.config.minion_config(self.cli['config'])
|
||||
self.opts = salt.config.monitor_config(self.cli['config'])
|
||||
|
||||
def __parse_cli(self):
|
||||
'''
|
||||
|
|
|
@ -34,12 +34,11 @@ def load_config(opts, path, env_var):
|
|||
else:
|
||||
print 'Missing configuration file: {0}'.format(path)
|
||||
|
||||
def prepend_root_dir(opts):
|
||||
def prepend_root_dir(opts, path_options):
|
||||
'''
|
||||
Prepends the options that represent filesystem paths with value of the
|
||||
'root_dir' option.
|
||||
'''
|
||||
path_options = ('pki_dir', 'cachedir', 'log_file')
|
||||
for path_option in path_options:
|
||||
opts[path_option] = os.path.normpath(
|
||||
os.sep.join([opts['root_dir'], opts[path_option]]))
|
||||
|
@ -89,7 +88,32 @@ def minion_config(path):
|
|||
opts['grains'] = salt.loader.grains(opts)
|
||||
|
||||
# Prepend root_dir to other paths
|
||||
prepend_root_dir(opts)
|
||||
prepend_root_dir(opts, ['pki_dir', 'cachedir', 'log_file'])
|
||||
|
||||
return opts
|
||||
|
||||
def monitor_config(path):
|
||||
'''
|
||||
Reads the minion configuration file and overrides with values from the monitor configuration.
|
||||
'''
|
||||
# Load minion config from (1) a file specified by $SALT_MINION_CONFIG or
|
||||
# (2) a file named 'minion' in the same directory as the monitor config file.
|
||||
minion_config_file = os.environ.get('SALT_MINION_CONFIG')
|
||||
if not minion_config_file:
|
||||
monitor_config_file = os.environ.get('SALT_MONITOR_CONFIG')
|
||||
if monitor_config_file:
|
||||
basedir = os.path.dirname(monitor_config_file)
|
||||
else
|
||||
basedir = os.path.dirname(path)
|
||||
minion_config_file = os.path.join(basedir, 'minion')
|
||||
opts = minion_config(minion_config_file)
|
||||
|
||||
# Overwrite minion options with monitor defaults
|
||||
opts.update({'log_file' : '/var/log/salt/monitor'})
|
||||
|
||||
# Overlay monitor config on minion config
|
||||
load_config(opts, path, 'SALT_MONITOR_CONFIG')
|
||||
prepend_root_dir(opts, ['log_file'])
|
||||
|
||||
return opts
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue