Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/diamond/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ def get_default_config(self):
# Default Poll Interval (seconds)
'interval': 300,

# Staggering collector runs is enabled by default
'stagger_collection': True,

# Default Event TTL (interval multiplier)
'ttl_multiplier': 2,

Expand Down
19 changes: 13 additions & 6 deletions src/diamond/utils/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
except ImportError:
setproctitle = None

from diamond.collector import str_to_bool
from diamond.utils.signals import signal_to_exception
from diamond.utils.signals import SIGALRMException
from diamond.utils.signals import SIGHUPException
Expand All @@ -35,18 +36,24 @@ def collector_process(collector, metric_queue, log):

interval = float(collector.config['interval'])

log.debug('Starting')
log.debug('Interval: %s seconds', interval)

# Validate the interval
if interval <= 0:
log.critical('interval of %s is not valid!', interval)
log.critical('Interval of %s is not valid!', interval)
sys.exit(1)

log.debug('Starting %s', collector.name)
log.debug('Interval: %s seconds', interval)

# Initially set stagger_offset to 0. If stagger_collection is enabled in
# the config, this value will soon be overridden.
stagger_offset = 0

# Start the next execution at the next window plus some stagger delay to
# avoid having all collectors running at the same time
next_window = math.floor(time.time() / interval) * interval
stagger_offset = random.uniform(0, interval - 1)

if str_to_bool(self.config['stagger_collection']):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this needs to be collector.config['stagger_collection'] instead of self.

But I have no capacity or ability to test this.

stagger_offset = random.uniform(0, interval - 1)

# Allocate time till the end of the window for the collector to run. With a
# minimum of 1 second
Expand Down Expand Up @@ -95,7 +102,7 @@ def collector_process(collector, metric_queue, log):
# us and end up with half a loaded config
signal.alarm(0)

log.info('Reloading config reload due to HUP')
log.info('Reloading config due to SIGHUP')
collector.load_config()
log.info('Config reloaded')

Expand Down