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  AsyncLineReaderMixin
 
class  AsyncLineReaderTimeoutMixin
 
class  ElasticReport
 
class  FDJsonHandler
 
class  FDJsonServer
 
class  FDOutputListener
 
class  JsonEncoder
 
class  LineHistoryEnd
 
class  LineHistoryStart
 

Functions

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 and produce es documents.")
 

Function Documentation

def esMonitoring.dt2time (   dt)

Definition at line 15 of file esMonitoring.py.

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

Definition at line 445 of file esMonitoring.py.

446 def handle_signal(signum, frame):
447  for proc in CURRENT_PROC:
448  proc.send_signal(signum)
def esMonitoring.launch_monitoring (   args)

Definition at line 382 of file esMonitoring.py.

References log().

383 def launch_monitoring(args):
384  es = ElasticReport(args=args)
385 
386  json_handler = FDJsonServer(es=es)
387  env = os.environ.copy()
388  env["DQM2_SOCKET"] = json_handler.fn
389 
390  def preexec():
391  try:
392  # ensure the child dies if we are SIGKILLED
393  import ctypes
394  libc = ctypes.CDLL("libc.so.6")
395  PR_SET_PDEATHSIG = 1
396  libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
397  except:
398  log("Failed to setup PR_SET_PDEATHSIG.")
399  pass
400 
401  p = subprocess.Popen(args.pargs, preexec_fn=preexec, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, env=env)
402  CURRENT_PROC.append(p)
403 
404  zlog = None
405  if args.zlog:
406  try:
407  relpath = os.path.dirname(__file__)
408  sys.path.append(relpath)
409  from ztee import GZipLog
410 
411  zlog_ = GZipLog(log_file=args.zlog)
412  es.update_doc({ "stdlog_gzip": args.zlog })
413 
414  log("Open gzip log file: %s" % args.zlog)
415  zlog = zlog_
416  except Exception, e:
417  log("Failed to setup zlog file: " + str(e))
418 
419  es.update_doc({ "pid": p.pid })
420  es.defaults()
421  es.make_report()
422 
423  log_handler = FDOutputListener(fd=p.stdout.fileno(), es=es, zlog=zlog, close_socket=json_handler)
424  log_handler.handle_line("-- starting process: %s --\n" % str(args.pargs))
425 
426  try:
427  #manager.event_loop(timeout=5, exit_fd=p.stdout.fileno())
428  asyncore.loop(timeout=5)
429  except select.error, e:
430  # we have this on ctrl+c
431  # just terminate the child
432  log("Select error (we will terminate): " + str(e))
433  p.terminate()
434 
435  # at this point the program is dead
436  r = p.wait()
437  log_handler.handle_line("\n-- process exit: %s --\n" % str(r))
438  log_handler.finish()
439 
440  es.update_doc({ "exit_code": r })
441  es.make_report()
442 
443  CURRENT_PROC.remove(p)
444  return r
def launch_monitoring
def esMonitoring.log (   s)

Definition at line 11 of file esMonitoring.py.

Referenced by esMonitoring.FDJsonHandler.handle_line(), launch_monitoring(), and esMonitoring.ElasticReport.make_report().

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

Variable Documentation

tuple esMonitoring.args = parser.parse_args()

Definition at line 454 of file esMonitoring.py.

list esMonitoring.CURRENT_PROC = []

Definition at line 381 of file esMonitoring.py.

tuple esMonitoring.parser = argparse.ArgumentParser(description="Monitor a child process and produce es documents.")

Definition at line 450 of file esMonitoring.py.