Skip to content

Commit

Permalink
Push internal module metrics to StatsD
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Nov 23, 2017
1 parent b495450 commit 501bfdc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion alignak_module_backend/broker/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import Queue
import logging

from alignak.stats import statsmgr
from alignak.basemodule import BaseModule
from alignak_backend_client.client import Backend, BackendException

Expand Down Expand Up @@ -82,6 +83,12 @@ def __init__(self, mod_conf):

self.default_realm = None

statsmgr.register(self.alias, 'broker',
statsd_host=getattr(mod_conf, 'statsd_host', ''),
statsd_port=getattr(mod_conf, 'statsd_port', ''),
statsd_prefix=getattr(mod_conf, 'statsd_prefix', ''),
statsd_enabled=(getattr(mod_conf, 'statsd_enabled', '0') != '0'))

self.url = getattr(mod_conf, 'api_url', 'http://localhost:5000')
self.backend = Backend(self.url, self.client_processes)
self.backend.token = getattr(mod_conf, 'token', '')
Expand Down Expand Up @@ -1046,16 +1053,22 @@ def main(self):

while not self.interrupted:
try:
logger.debug("queue length: %s", self.to_q.qsize())
queue_size = self.to_q.qsize()
logger.debug("queue length: %s", queue_size)
statsmgr.gauge('queue-size', queue_size)
start = time.time()

message = self.to_q.get_nowait()
brok_count = 0
for brok in message:
# Prepare and manage each brok in the queue message
brok.prepare()
self.manage_brok(brok)
brok_count = brok_count + 1
statsmgr.gauge('managed-broks-count', brok_count)

logger.debug("time to manage %s broks (%d secs)", len(message), time.time() - start)
statsmgr.timer('managed-broks-time', time.time() - start)
except Queue.Empty:
# logger.debug("No message in the module queue")
time.sleep(0.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ define module {
# received configuration)
# Default is 5 minutes
# load_protect_delay 300

# Export module metrics to a statsd server.
# By default at localhost:8125 (UDP) with the backend_broker prefix
# Default is not enabled
#statsd_host=localhost
#statsd_port=8125
#statsd_prefix=backend_broker
#statsd_enabled=0
}

0 comments on commit 501bfdc

Please sign in to comment.