Permalink
Browse files

Add : make the daemon appears on the process line (setproctitle mode)…

… so we know which is loading the module.
  • Loading branch information...
1 parent dbf0962 commit aaf16e3fb820b87a2960ff06cf41d8658c007110 @naparuba committed Jul 26, 2012
Showing with 26 additions and 5 deletions.
  1. +15 −1 shinken/basemodule.py
  2. +2 −0 shinken/modulesmanager.py
  3. +3 −1 shinken/satellite.py
  4. +5 −2 shinken/worker.py
  5. +1 −1 test/test_end_to_end.sh
View
@@ -109,6 +109,9 @@ def __init__(self, mod_conf):
self.process = None
self.illegal_char = compile(r'[^\w]')
self.init_try = 0
+ # We want to know where we are load from? (broker, scheduler, etc)
+ self.loaded_into = 'unknown'
+
def init(self):
"""Handle this module "post" init ; just before it'll be started.
@@ -117,6 +120,11 @@ def init(self):
"""
pass
+
+ def set_loaded_into(self, daemon_name):
+ self.loaded_into = daemon_name
+
+
def create_queues(self, manager=None):
"""The manager is None on android, but a true Manager() elsewhere
Create the shared queues that will be used by shinken daemon
@@ -132,6 +140,7 @@ def create_queues(self, manager=None):
self.from_q = manager.Queue()
self.to_q = manager.Queue()
+
def clear_queues(self, manager):
"""Release the resources associated to the queues of this instance"""
for q in (self.to_q, self.from_q):
@@ -146,6 +155,7 @@ def clear_queues(self, manager):
# q._callmethod('join_thread')
self.to_q = self.from_q = None
+
# Start this module process if it's external. if not -> donothing
def start(self):
@@ -169,6 +179,7 @@ def start(self):
self.properties['process'] = p # TODO: temporary
logger.info("%s is now started ; pid=%d" % (self.name, p.pid))
+
def __kill(self):
"""Sometime terminate() is not enough, we must "help"
external modules to die...
@@ -200,15 +211,18 @@ def stop_process(self):
def get_name(self):
return self.name
+
def has(self, prop):
"""The classic has: do we have a prop or not?"""
return hasattr(self, prop)
+
# For in scheduler modules, we will not send all broks to external
# modules, only what they really want
def want_brok(self, b):
return True
+
def manage_brok(self, brok):
"""Request the module to manage the given brok.
There a lot of different possible broks to manage.
@@ -247,7 +261,7 @@ def do_loop_turn(self):
def set_proctitle(self, name):
try:
from setproctitle import setproctitle
- setproctitle("shinken-module: %s" % name)
+ setproctitle("shinken-%s module: %s" % (self.loaded_into, name))
except:
pass
@@ -159,6 +159,8 @@ def get_instances(self):
try:
mod_conf.properties = module.properties.copy()
inst = module.get_instance(mod_conf)
+ # Give the module the data to which module it is load from
+ inst.set_loaded_into(self.modules_type)
if inst is None: # None = Bad thing happened :)
logger.info("get_instance for module %s returned None!" % (mod_conf.get_name()))
continue
@@ -423,8 +423,10 @@ def create_and_launch_worker(self, module_name='fork', mortal=True):
target = module.work
if target is None:
return
+ # We want to give to the Worker the name of the daemon (poller or reactionner)
+ cls_name = self.__class__.__name__.lower()
w = Worker(1, q, self.returns_queue, self.processes_by_worker, \
- mortal=mortal, max_plugins_output_length=self.max_plugins_output_length, target=target)
+ mortal=mortal, max_plugins_output_length=self.max_plugins_output_length, target=target, loaded_into=cls_name)
w.module_name = module_name
# save this worker
self.workers[w.id] = w
View
@@ -60,7 +60,7 @@ class Worker:
_timeout = None
_c = None
- def __init__(self, id, s, returns_queue, processes_by_worker, mortal=True, timeout=300, max_plugins_output_length=8192, target=None):
+ def __init__(self, id, s, returns_queue, processes_by_worker, mortal=True, timeout=300, max_plugins_output_length=8192, target=None, loaded_into='unknown'):
self.id = self.__class__.id
self.__class__.id += 1
@@ -77,6 +77,9 @@ def __init__(self, id, s, returns_queue, processes_by_worker, mortal=True, timeo
self.returns_queue = returns_queue
self.max_plugins_output_length = max_plugins_output_length
self.i_am_dying = False
+ # Keep a trace where the worker is launch from (poller or reactionner?)
+ self.loaded_into = loaded_into
+
def is_mortal(self):
return self._mortal
@@ -268,7 +271,7 @@ def work(self, s, returns_queue, c):
def set_proctitle(self):
try:
from setproctitle import setproctitle
- setproctitle("shinken-worker")
+ setproctitle("shinken-%s worker" % self.loaded_into)
except:
pass
@@ -35,7 +35,7 @@ echo "NB CPUS: " $NB_CPUS
# check for a process existance with good number
function check_process_nb {
- NB=`ps -ef | grep python | grep -v grep | grep "shinken-"$1 | wc -l`
+ NB=`ps -ef | grep -v grep | grep "shinken-"$1 | wc -l`
if [ $NB != "$2" ]
then
echo "Error: There is not enough $1 launched (only $NB)."

0 comments on commit aaf16e3

Please sign in to comment.