From 58756abfc3d70f860653df66af30c12b83be69a5 Mon Sep 17 00:00:00 2001 From: Azef1 Date: Tue, 12 Jul 2016 12:20:54 +0200 Subject: [PATCH] Add options to enable\disable sending state In graphite2.cfg, options are: state_enable 1 #1=enable send state / 0=disable state_host 1 #1=enable send state for host / 0=disable state_service 1 #1=enable send state for service / 0=disable --- module/module.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/module/module.py b/module/module.py index 44b96e7..5e704bb 100644 --- a/module/module.py +++ b/module/module.py @@ -82,6 +82,14 @@ def __init__(self, modconf): logger.info('[Graphite] Configuration - maximum cache commit volume: %d packets', self.cache_commit_volume) self.cache = deque(maxlen=self.cache_max_length) + # Options to send state + self.state_enable = int(getattr(modconf, 'state_enable', '0')) + logger.info('[Graphite] Configuration - Send state to Graphite: %d ', self.state_enable) + self.state_host = int(getattr(modconf, 'state_host', '0')) + logger.info('[Graphite] Configuration - Send state for hosts to Graphite: %d ', self.state_host) + self.state_service = int(getattr(modconf, 'state_service', '0')) + logger.info('[Graphite] Configuration - Send state for service to Graphite: %d ', self.state_service) + # Used to reset check time into the scheduled time. # Carbon/graphite does not like latency data and creates blanks in graphs # Every data with "small" latency will be considered create at scheduled time @@ -303,16 +311,17 @@ def manage_service_check_result_brok(self, b): path = '.'.join((hname, self.graphite_data_source, desc)) else: path = '.'.join((hname, desc)) - + #Send state to Graphite state_query = [] state_query.append("%s.available %s %d" % (path, state_id, check_time)) state_packet = '\n'.join(state_query) + '\n' #logger.error("---SERVICE--- %s", state_packet) - try: - self.send_packet(state_packet) - except IOError: - logger.error("[Graphite broker] Failed sendind state o the Graphite Carbon.") + if (self.state_enable == 1 and self.state_service == 1): + try: + self.send_packet(state_packet) + except IOError: + logger.error("[Graphite broker] Failed sending state to the Graphite Carbon.") if len(couples) == 0: logger.debug("[Graphite] no metrics to send ...") @@ -376,11 +385,11 @@ def manage_host_check_result_brok(self, b): state_query.append("%s.available %s %d" % (path, state_id, check_time)) state_packet = '\n'.join(state_query) + '\n' #logger.error("---HOST--- %s", state_packet) - try: - self.send_packet(state_packet) - except IOError: - logger.error("[Graphite broker] Failed sendind state o the Graphite Carbon.") - + if (self.state_enable == 1 and self.state_host == 1): + try: + self.send_packet(state_packet) + except IOError: + logger.error("[Graphite broker] Failed sending state to the Graphite Carbon.") if len(couples) == 0: logger.debug("[Graphite] no metrics to send ...") return