Made collection times configurable

The collector now checks the yaml configuration file for a variable
called collect_period.
If collect_period is specified, the collector will skip calling the
plugin and collecting metrics for the plugin until the specified
number of seconds has passed.

Change-Id: I423b1f14d4b0580e625e5f57c729c4a6c9923a93
This commit is contained in:
Andrea Adams 2016-07-19 17:02:50 -06:00
parent 434576b58b
commit fb4ee3a588
3 changed files with 38 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
init_config:
# These are Neutron credentials, [keystone_authtoken] in /etc/neutron/neutron.conf
admin_password: password
@ -29,6 +29,12 @@ init_config:
# If set, will submit the health related metrics from ovs-vsctl command
# output for the given network interface.
use_health_metrics = true
# If specified, the collector will skip calling the plugin until the specified
# number of seconds has passed.
# NOTE: Collection is dictated by the default collection frequency therefor
# collect_period should be evenly divisible by the default collection frequency
# otherwise the plugin will be called on the collection run after the specified time
collect_period = 300
instances:
# Instances are not used and should be empty in `ovs.yaml` because like the

View File

@ -229,6 +229,12 @@ instances:
#### init_config
In the init_config section you can specify an arbitrary number of global name:value pairs that will be available on every run of the check in self.init_config.
Here you can specify a collection frequency specific to the plugin by setting collect_period.
The global frequency at which all plugins are run is specified by the variable "check_frequency" defined in https://github.com/openstack/monasca-agent/blob/master/docs/Agent.md.
Under normal and default conditions when a plugin runs all the metrics are collected and sent. For example, if check_frequency=30, by default the plugin will be run every 30 seconds and the metrics will be sent.
The variable "collect_period" allows each plugins collect period to be further adjusted to a value greater than the frequency at which the plugin is run specified by "check_frequency", such that when the collection run starts, the plugin might not be called. For example, if check_frequency=30 and collect_period=600, the plugin will be called and metrics sent every 600 seconds. This allows fewer metrics to be sent.
The "collect_period" should be evenly divisible by the "check_frequency". For example, if you want the plugin to collect and send metrics every 600 seconds (10 minutes), and the global check_frequency=30, then the collect_period should be set to 600.
If the "collect_period" is not evenly divisible by the "check_frequency" then the "collect_period" will get rounded up to the nearest multiple of the "check_frequency". For example, if the collect_period=45 and the global check_frequency=30, then the "collect_period" will get rounded up to 60 and the plugin will get called and send metrics every 60 seconds.
#### instances
The instances section is a list of instances that this check will be run against. Your actual check() method is run once per instance. The name:value pairs for each instance specify details about the instance that are necessary for the check.
@ -1660,4 +1666,4 @@ The following ceilometer processes are monitored, if they exist when the monasca
=======
# License
(C) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP
(C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP

View File

@ -48,9 +48,26 @@ class Collector(util.Dimensions):
self.pool_full_count = 0
self.collection_times = {}
self.collection_results = {}
self.collect_runs = 0
for check in initialized_checks_d:
self.collection_times[check.name] = {'check': check,
'last_collect_time': 99999999}
derived_collect_periods = 1
if 'collect_period' in check.init_config:
if check.init_config['collect_period'] < 0:
log.warn('Invalid negative time parameter. '
'collect_period for %s will be reset '
'to default' % check.name)
else:
# This equation calculates on which nth run the plugin
# gets called. It converts the collect_period from seconds
# to an integer which holds the collection round the
# plugin should get called on.
derived_collect_periods = (
((check.init_config['collect_period'] - 1)
/ agent_config['check_freq']) + 1)
self.collection_times[check.name] = {
'check': check,
'last_collect_time': 99999999,
'derived_collect_periods': derived_collect_periods}
self.pool_full_max_retries = int(self.agent_config.get('pool_full_max_retries',
4))
@ -201,11 +218,16 @@ class Collector(util.Dimensions):
if check.name in self.collection_results:
log.warning('Plugin %s is already running, skipping' % check.name)
continue
if self.collect_runs % entry['derived_collect_periods'] != 0:
log.debug('%s has not skipped enough collection periods yet. '
'Skipping.' % check.name)
continue
log.debug('Starting plugin %s, old collect time %d' %
(check.name, last_collect_time))
async_result = self.pool.apply_async(self.run_single_check, [check])
self.collection_results[check.name] = {'result': async_result,
'start_time': start_time}
self.collect_runs += 1
def run_checks_d(self, check_frequency):
"""Run defined checks_d checks using the Thread Pool.