Skip to content

Commit

Permalink
Add options to enable\disable sending state
Browse files Browse the repository at this point in the history
In graphite2.cfg, options are:
   state_enable 1 shinken-monitoring#1=enable send state / 0=disable
   state_host   1 shinken-monitoring#1=enable send state for host / 0=disable
   state_service 1 shinken-monitoring#1=enable send state for service / 0=disable
  • Loading branch information
Azef1 authored Jul 12, 2016
1 parent 886a6ec commit 58756ab
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ...")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 58756ab

Please sign in to comment.