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 452 of file esMonitoring.py.

453 def handle_signal(signum, frame):
454  for proc in CURRENT_PROC:
455  proc.send_signal(signum)
def esMonitoring.launch_monitoring (   args)

Definition at line 387 of file esMonitoring.py.

References log().

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

list esMonitoring.CURRENT_PROC = []

Definition at line 386 of file esMonitoring.py.

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

Definition at line 457 of file esMonitoring.py.