CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
esMonitoring Namespace Reference

Classes

class  DescriptorCapture
 
class  ElasticReport
 
class  History
 
class  JsonInput
 

Functions

def create_fifo
 
def dt2time
 
def handle_signal
 
def launch_monitoring
 
def log
 

Variables

tuple args = parser.parse_args()
 
list CURRENT_PROC = []
 
tuple parser = argparse.ArgumentParser(description="Monitor a child process - produces elastic search documents.")
 

Function Documentation

def esMonitoring.create_fifo ( )

Definition at line 292 of file esMonitoring.py.

References log().

Referenced by launch_monitoring().

293 def create_fifo():
294  prefix = "/tmp"
295  if os.path.isdir("/tmp/dqm_monitoring"):
296  prefix = "/tmp/dqm_monitoring"
297 
298  base = ".es_monitoring_pid%08d" % os.getpid()
299  fn = os.path.join(prefix, base)
300 
301  if os.path.exists(fn):
302  os.unlink(fn)
303 
304  os.mkfifo(fn, 0600)
305  if not os.path.exists(fn):
306  log("Failed to create fifo file: %s" % fn)
307  sys.exit(-1)
308 
309  atexit.register(os.unlink, fn)
310  return fn
def esMonitoring.dt2time (   dt)

Definition at line 14 of file esMonitoring.py.

14 
15 def dt2time(dt):
16  # convert datetime timstamp to unix
17  return time.mktime(dt.timetuple())
def esMonitoring.handle_signal (   signum,
  frame 
)

Definition at line 368 of file esMonitoring.py.

369 def handle_signal(signum, frame):
370  for proc in CURRENT_PROC:
371  proc.send_signal(signum)
def esMonitoring.launch_monitoring (   args)

Definition at line 312 of file esMonitoring.py.

References create_fifo(), and log().

313 def launch_monitoring(args):
314  fifo = create_fifo()
315  mon_fd = os.open(fifo, os.O_RDONLY | os.O_NONBLOCK)
316 
317  def preexec():
318  # this should only be open on a parent
319  os.close(mon_fd)
320 
321  # open fifo once (hack)
322  # so there is *always* at least one writter
323  # which closes with the executable
324  os.open(fifo, os.O_WRONLY)
325 
326  try:
327  # ensure the child dies if we are SIGKILLED
328  import ctypes
329  libc = ctypes.CDLL("libc.so.6")
330  PR_SET_PDEATHSIG = 1
331  libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
332  except:
333  log("Failed to setup PR_SET_PDEATHSIG.")
334  pass
335 
336  env = os.environ
337  env["DQMMON_UPDATE_PIPE"] = fifo
338 
339  p = subprocess.Popen(args.pargs, preexec_fn=preexec, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
340  CURRENT_PROC.append(p)
341 
342  mon_file = os.fdopen(mon_fd)
343  s_hist = History()
344  s_json = JsonInput()
345  report_sink = ElasticReport(pid=p.pid, history=s_hist, json=s_json, args=args)
346 
347  stdout_cap = DescriptorCapture(p.stdout, write_files=[sys.stdout, s_hist, report_sink, ], )
348  stderr_cap = DescriptorCapture(p.stderr, write_files=[sys.stderr, s_hist, report_sink, ], )
349  stdmon_cap = DescriptorCapture(mon_file, write_files=[s_json, report_sink, ],)
350 
351  fs = [stdout_cap, stderr_cap, stdmon_cap]
352  try:
353  DescriptorCapture.event_loop(fs, timeout=1000, timeout_call=report_sink.flush)
354  except select.error, e:
355  # we have this on ctrl+c
356  # just terminate the child
357  log("Select error (we will terminate): " + str(e))
358  p.terminate()
359 
360  # at this point the program is dead
361  r = p.wait()
362  CURRENT_PROC.remove(p)
363 
364  report_sink.update_doc({ "exit_code": r })
365  report_sink.make_report()
366 
367  return r
def launch_monitoring
def esMonitoring.log (   s)

Definition at line 10 of file esMonitoring.py.

Referenced by esMonitoring.DescriptorCapture.close_in(), create_fifo(), launch_monitoring(), and esMonitoring.JsonInput.parse_line().

10 
11 def log(s):
12  sys.stderr.write("m: " + s + "\n");
13  sys.stderr.flush()

Variable Documentation

tuple esMonitoring.args = parser.parse_args()

Definition at line 377 of file esMonitoring.py.

list esMonitoring.CURRENT_PROC = []

Definition at line 311 of file esMonitoring.py.

tuple esMonitoring.parser = argparse.ArgumentParser(description="Monitor a child process - produces elastic search documents.")

Definition at line 373 of file esMonitoring.py.