Skip to content

Commit

Permalink
Merge pull request #651 from Alignak-monitoring/daemons-name
Browse files Browse the repository at this point in the history
Daemons process title name
  • Loading branch information
David Durieux authored Dec 19, 2016
2 parents a99ffde + 7921660 commit ba57491
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 65 deletions.
17 changes: 11 additions & 6 deletions alignak/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class Daemon(object):
"""

properties = {
'daemon_type':
StringProp(default='unknown'),
# workdir is relative to $(dirname "$0"/..)
# where "$0" is the path of the file being executed,
# in python normally known as:
Expand Down Expand Up @@ -435,12 +437,12 @@ def dump_memory():
except ImportError:
logger.warning('I do not have the module guppy for memory dump, please install it')

def load_modules_manager(self):
def load_modules_manager(self, daemon_name):
"""Instantiate Modulesmanager and load the SyncManager (multiprocessing)
:return: None
"""
self.modules_manager = ModulesManager(self.name, self.sync_manager,
self.modules_manager = ModulesManager(daemon_name, self.sync_manager,
max_queue_size=getattr(self, 'max_queue_size', 0))

def change_to_workdir(self):
Expand Down Expand Up @@ -686,7 +688,7 @@ def _create_manager():
manager.start()
return manager

def do_daemon_init_and_start(self, daemon_name=None):
def do_daemon_init_and_start(self):
"""Main daemon function.
Clean, allocates, initializes and starts all necessary resources to go in daemon mode.
Expand All @@ -695,7 +697,7 @@ def do_daemon_init_and_start(self, daemon_name=None):
:type daemon_name: str
:return: False if the HTTP daemon can not be initialized, else True
"""
self.set_proctitle(daemon_name)
self.set_proctitle()
self.change_to_user_group()
self.change_to_workdir()
self.check_parallel_run()
Expand Down Expand Up @@ -999,6 +1001,7 @@ def set_exit_handler(self):
signal.SIGUSR2, signal.SIGHUP):
signal.signal(sig, func)

# pylint: disable=no-member
def set_proctitle(self, daemon_name=None):
"""Set the proctitle of the daemon
Expand All @@ -1008,9 +1011,11 @@ def set_proctitle(self, daemon_name=None):
:return: None
"""
if daemon_name:
setproctitle("alignak-%s %s" % (self.name, daemon_name))
setproctitle("alignak-%s %s" % (self.daemon_type, daemon_name))
if hasattr(self, 'modules_manager'):
self.modules_manager.set_daemon_name(daemon_name)
else:
setproctitle("alignak-%s" % self.name)
setproctitle("alignak-%s" % self.daemon_type)

def get_header(self):
""" Get the log file header
Expand Down
12 changes: 10 additions & 2 deletions alignak/daemons/arbiterdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
from alignak.stats import statsmgr
from alignak.brok import Brok
from alignak.external_command import ExternalCommand
from alignak.property import BoolProp, PathProp, IntegerProp
from alignak.property import BoolProp, PathProp, IntegerProp, StringProp
from alignak.http.arbiter_interface import ArbiterInterface

logger = logging.getLogger(__name__) # pylint: disable=C0103
Expand All @@ -90,6 +90,8 @@ class Arbiter(Daemon): # pylint: disable=R0902
"""
properties = Daemon.properties.copy()
properties.update({
'daemon_type':
StringProp(default='arbiter'),
'pidfile':
PathProp(default='arbiterd.pid'),
'port':
Expand Down Expand Up @@ -285,8 +287,11 @@ def load_monitoring_config_file(self): # pylint: disable=R0915
"with the value '%s'."
" Thanks." % (self.config_name, socket.gethostname()))

# Set my own process title
self.set_proctitle(self.myself.get_name())

# Ok it's time to load the module manager now!
self.load_modules_manager()
self.load_modules_manager(self.myself.get_name())
# we request the instances without them being *started*
# (for those that are concerned ("external" modules):
# we will *start* these instances after we have been daemonized (if requested)
Expand Down Expand Up @@ -540,6 +545,9 @@ def main(self):
self.look_for_early_exit()
self.do_daemon_init_and_start()

# Set my own process title
self.set_proctitle(self.myself.get_name())

# ok we are now fully daemonized (if requested)
# now we can start our "external" modules (if any):
self.modules_manager.start_external_instances()
Expand Down
54 changes: 29 additions & 25 deletions alignak/daemons/brokerdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
from alignak.objects import *
from alignak.misc.serialization import unserialize, AlignakClassLookupException
from alignak.satellite import BaseSatellite
from alignak.property import PathProp, IntegerProp
from alignak.property import PathProp, IntegerProp, StringProp
from alignak.util import sort_by_ids
from alignak.stats import statsmgr
from alignak.http.client import HTTPClient, HTTPEXCEPTIONS
Expand All @@ -88,9 +88,14 @@ class Broker(BaseSatellite):
"""
properties = BaseSatellite.properties.copy()
properties.update({
'pidfile': PathProp(default='brokerd.pid'),
'port': IntegerProp(default=7772),
'local_log': PathProp(default='brokerd.log'),
'daemon_type':
StringProp(default='broker'),
'pidfile':
PathProp(default='brokerd.pid'),
'port':
IntegerProp(default=7772),
'local_log':
PathProp(default='brokerd.log'),
})

def __init__(self, config_file, is_daemon, do_replace, debug, debug_file):
Expand Down Expand Up @@ -323,12 +328,10 @@ def manage_brok(self, brok):
for mod in self.modules_manager.get_internal_instances():
try:
mod.manage_brok(brok)
except Exception, exp: # pylint: disable=W0703
logger.debug(str(exp.__dict__))
except Exception as exp: # pylint: disable=broad-except
logger.warning("The mod %s raise an exception: %s, I'm tagging it to restart later",
mod.get_name(), str(exp))
logger.warning("Exception type: %s", type(exp))
logger.warning("Back trace of this kill: %s", traceback.format_exc())
logger.exception(exp)
self.modules_manager.set_to_restart(mod)

def add_broks_to_queue(self, broks):
Expand Down Expand Up @@ -397,23 +400,24 @@ def get_new_broks(self, i_type='scheduler'):
else: # no con? make the connection
self.pynag_con_init(sched_id, i_type=i_type)
# Ok, con is not known, so we create it
except KeyError, exp:
except KeyError as exp:
logger.debug("Key error for get_broks : %s", str(exp))
self.pynag_con_init(sched_id, i_type=i_type)
except HTTPEXCEPTIONS, exp:
except HTTPEXCEPTIONS as exp:
logger.warning("Connection problem to the %s %s: %s",
i_type, links[sched_id]['name'], str(exp))
logger.exception(exp)
links[sched_id]['con'] = None
# scheduler must not #be initialized
except AttributeError, exp:
except AttributeError as exp:
logger.warning("The %s %s should not be initialized: %s",
i_type, links[sched_id]['name'], str(exp))
logger.exception(exp)
# scheduler must not have checks
# What the F**k? We do not know what happened,
# so.. bye bye :)
except Exception, err: # pylint: disable=W0703
logger.error(str(err))
logger.error(traceback.format_exc())
except Exception as exp: # pylint: disable=broad-except
logger.exception(exp)
sys.exit(1)

def get_retention_data(self):
Expand Down Expand Up @@ -449,6 +453,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
:return: None
"""

with self.conf_lock:
conf = unserialize(self.new_conf, True)
self.new_conf = None
Expand All @@ -475,9 +480,8 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912

logger.debug("[%s] Sending us configuration %s", self.name, conf)

# If we've got something in the schedulers, we do not
# want it anymore
# self.schedulers.clear()
# Get our Schedulers
logger.info("[%s] schedulers: %s", self.name, conf['schedulers'])
for sched_id in conf['schedulers']:
# Must look if we already have it to do not overdie our broks

Expand Down Expand Up @@ -519,6 +523,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
logger.info(" - %s ", daemon['name'])

# Now get arbiter
logger.info("[%s] arbiters: %s", self.name, conf['arbiters'])
for arb_id in conf['arbiters']:
# Must look if we already have it
already_got = arb_id in self.arbiters
Expand Down Expand Up @@ -553,6 +558,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
logger.info(" - %s ", daemon['name'])

# Now for pollers
logger.info("[%s] pollers: %s", self.name, conf['pollers'])
for pol_id in conf['pollers']:
# Must look if we already have it
already_got = pol_id in self.pollers
Expand Down Expand Up @@ -588,6 +594,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
logger.info(" - %s ", daemon['name'])

# Now reactionners
logger.info("[%s] reactionners: %s", self.name, conf['reactionners'])
for rea_id in conf['reactionners']:
# Must look if we already have it
already_got = rea_id in self.reactionners
Expand Down Expand Up @@ -623,6 +630,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
logger.info(" - %s ", daemon['name'])

# Now receivers
logger.debug("[%s] receivers: %s", self.name, conf['receivers'])
for rec_id in conf['receivers']:
# Must look if we already have it
already_got = rec_id in self.receivers
Expand Down Expand Up @@ -673,7 +681,7 @@ def setup_new_conf(self): # pylint: disable=R0915,R0912
os.environ['TZ'] = use_timezone
time.tzset()

# Connection init with Schedulers
# Initialize connection with Schedulers, Pollers and Reactionners
for sched_id in self.schedulers:
self.pynag_con_init(sched_id, i_type='scheduler')

Expand Down Expand Up @@ -792,14 +800,12 @@ def do_loop_turn(self):
for mod in ext_modules:
try:
mod.to_q.put(to_send)
except Exception, exp: # pylint: disable=W0703
except Exception as exp: # pylint: disable=broad-except
# first we must find the modules
logger.debug(str(exp.__dict__))
logger.warning("The mod %s queue raise an exception: %s, "
"I'm tagging it to restart later",
mod.get_name(), str(exp))
logger.warning("Exception type: %s", type(exp))
logger.warning("Back trace of this kill: %s", traceback.format_exc())
logger.exception(exp)
self.modules_manager.set_to_restart(mod)

# No more need to send them
Expand Down Expand Up @@ -853,8 +859,6 @@ def do_loop_turn(self):
self.timeout = self.timeout - (end - begin)
self.timeout = 1.0

# print "get new broks watch new conf 1: end", len(self.broks)

# Say to modules it's a new tick :)
self.hook_point('tick')

Expand All @@ -873,7 +877,7 @@ def main(self):

self.do_daemon_init_and_start()

self.load_modules_manager()
self.load_modules_manager(self.name)

# We wait for initial conf
self.wait_for_initial_conf()
Expand Down
13 changes: 9 additions & 4 deletions alignak/daemons/pollerdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
This modules provides class for the Poller daemon
"""
from alignak.satellite import Satellite
from alignak.property import PathProp, IntegerProp
from alignak.property import PathProp, IntegerProp, StringProp


class Poller(Satellite):
Expand All @@ -60,9 +60,14 @@ class Poller(Satellite):

properties = Satellite.properties.copy()
properties.update({
'pidfile': PathProp(default='pollerd.pid'),
'port': IntegerProp(default=7771),
'local_log': PathProp(default='pollerd.log'),
'daemon_type':
StringProp(default='poller'),
'pidfile':
PathProp(default='pollerd.pid'),
'port':
IntegerProp(default=7771),
'local_log':
PathProp(default='pollerd.log'),
})

def __init__(self, config_file, is_daemon, do_replace, debug, debug_file):
Expand Down
13 changes: 9 additions & 4 deletions alignak/daemons/reactionnerdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"""

from alignak.satellite import Satellite
from alignak.property import PathProp, IntegerProp
from alignak.property import PathProp, IntegerProp, StringProp


class Reactionner(Satellite):
Expand All @@ -73,9 +73,14 @@ class Reactionner(Satellite):

properties = Satellite.properties.copy()
properties.update({
'pidfile': PathProp(default='reactionnerd.pid'),
'port': IntegerProp(default=7769),
'local_log': PathProp(default='reactionnerd.log'),
'daemon_type':
StringProp(default='reactionner'),
'pidfile':
PathProp(default='reactionnerd.pid'),
'port':
IntegerProp(default=7769),
'local_log':
PathProp(default='reactionnerd.log'),
})

def __init__(self, config_file, is_daemon, do_replace, debug, debug_file):
Expand Down
6 changes: 4 additions & 2 deletions alignak/daemons/receiverdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

from alignak.misc.serialization import unserialize
from alignak.satellite import Satellite
from alignak.property import PathProp, IntegerProp
from alignak.property import PathProp, IntegerProp, StringProp
from alignak.external_command import ExternalCommand, ExternalCommandManager
from alignak.http.client import HTTPEXCEPTIONS
from alignak.stats import statsmgr
Expand All @@ -76,6 +76,8 @@ class Receiver(Satellite):

properties = Satellite.properties.copy()
properties.update({
'daemon_type':
StringProp(default='receiver'),
'pidfile':
PathProp(default='receiverd.pid'),
'port':
Expand Down Expand Up @@ -409,7 +411,7 @@ def main(self):

self.do_daemon_init_and_start()

self.load_modules_manager()
self.load_modules_manager(self.name)

# We wait for initial conf
self.wait_for_initial_conf()
Expand Down
15 changes: 13 additions & 2 deletions alignak/daemons/schedulerdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from alignak.external_command import ExternalCommandManager
from alignak.daemon import Daemon
from alignak.http.scheduler_interface import SchedulerInterface
from alignak.property import PathProp, IntegerProp
from alignak.property import PathProp, IntegerProp, StringProp
from alignak.satellite import BaseSatellite
from alignak.stats import statsmgr

Expand All @@ -79,6 +79,8 @@ class Alignak(BaseSatellite):

properties = BaseSatellite.properties.copy()
properties.update({
'daemon_type':
StringProp(default='scheduler'),
'pidfile':
PathProp(default='schedulerd.pid'),
'port':
Expand Down Expand Up @@ -252,6 +254,15 @@ def setup_new_conf(self):
logger.debug("Conf received at %d. Un-serialized in %d secs", t00, time.time() - t00)
self.new_conf = None

if 'scheduler_name' in new_c:
name = new_c['scheduler_name']
else:
name = instance_name
self.name = name

# Set my own process title
self.set_proctitle(self.name)

# Tag the conf with our data
self.conf = conf
self.conf.push_flavor = new_c['push_flavor']
Expand Down Expand Up @@ -375,7 +386,7 @@ def main(self):

self.do_daemon_init_and_start()

self.load_modules_manager()
self.load_modules_manager(self.name)

self.uri = self.http_daemon.uri
logger.info("[Scheduler] General interface is at: %s", self.uri)
Expand Down
Loading

0 comments on commit ba57491

Please sign in to comment.