Skip to content

Commit

Permalink
Enh : Set module/worker processes name to be more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Bour committed Jul 26, 2012
1 parent 8ea7abb commit dbf0962
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions setup.py
Expand Up @@ -607,6 +607,9 @@ def update_file_with_string(infilename, outfilename, match, new_string):
install_requires=[
required_pkgs
],
extras_require={
'setproctitle': ['setproctitle']
},

scripts=glob('bin/shinken-[!_]*'),

Expand Down
9 changes: 9 additions & 0 deletions shinken/basemodule.py
Expand Up @@ -244,8 +244,17 @@ def do_loop_turn(self):
"""
raise NotImplementedError()

def set_proctitle(self, name):
try:
from setproctitle import setproctitle
setproctitle("shinken-module: %s" % name)
except:
pass

def main(self):
"""module "main" method. Only used by external modules."""
self.set_proctitle(self.name)

self.set_signal_handler()
logger.info("[%s[%d]]: Now running.." % (self.name, os.getpid()))
while not self.interrupted:
Expand Down
2 changes: 2 additions & 0 deletions shinken/modules/android_sms.py
Expand Up @@ -194,6 +194,8 @@ def read_and_parse_sms(self):
# c = Control Queue for the worker
def work(self, s, returns_queue, c):
print "Module Android started!"
self.set_proctitle(self.name)

self.android = android.Android()
timeout = 1.0
self.checks = []
Expand Down
1 change: 1 addition & 0 deletions shinken/modules/collectd_arbiter.py
Expand Up @@ -297,6 +297,7 @@ def __init__(self, modconf):

# When you are in "external" mode, that is the main loop of your process
def main(self):
self.set_proctitle(self.name)
self.set_exit_handler()

last_check = 0.0
Expand Down
2 changes: 2 additions & 0 deletions shinken/modules/livestatus_broker/livestatus_broker.py
Expand Up @@ -162,6 +162,8 @@ def set_debug(self):
os.dup2(fdtemp, 2) # standard error (2)

def main(self):
self.set_proctitle(self.name)

self.log = logger
self.log.load_obj(self)
# Daemon like init
Expand Down
1 change: 1 addition & 0 deletions shinken/modules/named_pipe.py
Expand Up @@ -107,6 +107,7 @@ def get(self):

# When you are in "external" mode, that is the main loop of your process
def main(self):
self.set_proctitle(self.name)
self.set_exit_handler()

self.open()
Expand Down
2 changes: 2 additions & 0 deletions shinken/modules/npcdmod_broker.py
Expand Up @@ -196,6 +196,8 @@ def rotate(self):
# This version does not use a signal-based timer yet. Rotation is triggered
# by a constant flow of status update broks
def main(self):
self.set_proctitle(self.name)

self.set_exit_handler()
self.rotate()
last_rotated = time.time()
Expand Down
2 changes: 2 additions & 0 deletions shinken/modules/nrpe_poller.py
Expand Up @@ -465,6 +465,8 @@ def work(self, s, returns_queue, c):
print "[Nrpe] Module NRPE started!"
## restore default signal handler for the workers:
signal.signal(signal.SIGTERM, signal.SIG_DFL)
self.set_proctitle(self.name)

timeout = 1.0
self.checks = []

Expand Down
2 changes: 2 additions & 0 deletions shinken/modules/nsca.py
Expand Up @@ -180,6 +180,8 @@ def process_check_result(self, databuffer, IV):

# When you are in "external" mode, that is the main loop of your process
def main(self):
self.set_proctitle(self.name)

self.set_exit_handler()
backlog = 5
size = 8192
Expand Down
1 change: 1 addition & 0 deletions shinken/modules/status_dat_broker/status_dat_broker.py
Expand Up @@ -370,6 +370,7 @@ def update_element(self, e, data):
setattr(e, prop, data[prop])

def main(self):
self.set_proctitle(self.name)
self.set_exit_handler()
last_generation = time.time()
objects_cache_written = False
Expand Down
2 changes: 2 additions & 0 deletions shinken/modules/tsca.py
Expand Up @@ -166,6 +166,8 @@ def post_command(self, timestamp, rc, hostname, service, output):

# When you are in "external" mode, that is the main loop of your process
def main(self):
self.set_proctitle(self.name)

self.set_exit_handler()
try:
handler = StateServiceHandler(self)
Expand Down
2 changes: 2 additions & 0 deletions shinken/modules/webui_broker/webui_broker.py
Expand Up @@ -125,6 +125,8 @@ def want_brok(self, b):
return self.rg.want_brok(b)

def main(self):
self.set_proctitle(self.name)

self.log = logger
self.log.load_obj(self)

Expand Down
3 changes: 3 additions & 0 deletions shinken/modules/ws_arbiter.py
Expand Up @@ -117,6 +117,9 @@ def init_http(self):
def main(self):
global app

# Change process name (seen in ps or top)
self.set_proctitle(self.name)

# It's an external module, so we need to be sure that we manage
# the signals
self.set_exit_handler()
Expand Down
11 changes: 11 additions & 0 deletions shinken/worker.py
Expand Up @@ -213,6 +213,9 @@ def work(self, s, returns_queue, c):
# but on android, we are a thread, so don't do it
if not is_android:
signal.signal(signal.SIGTERM, signal.SIG_DFL)

self.set_proctitle()

timeout = 1.0
self.checks = []
self.returns_queue = returns_queue
Expand Down Expand Up @@ -261,3 +264,11 @@ def work(self, s, returns_queue, c):
timeout -= time.time() - begin
if timeout < 0:
timeout = 1.0

def set_proctitle(self):
try:
from setproctitle import setproctitle
setproctitle("shinken-worker")
except:
pass

3 comments on commit dbf0962

@naparuba
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I4ll have to change the names, to show the shinken-poller module : (so keep shinken-poller or shinken-broker name) because of the tests (and to know which daemon is launching the module). I'm on it :)

If we don't, it break the tests :p (tests are counting the processus by their names :p ).

@naparuba
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I push the code.

Now instead of shinken worker it will be :
shinken-poller worker

and instead of
shinken module : LiveSTatus
it will be :
shinken-broker module : LiveStatus.

I think the setproctitle should be installed by default :)

@gbour
Copy link
Contributor

@gbour gbour commented on dbf0962 Jul 26, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arggg, I launched shorttests but didn't see the error.
Thanks you naparuba

Please sign in to comment.