CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 453 of file esMonitoring.py.

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

Definition at line 388 of file esMonitoring.py.

References log(), and str.

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

list esMonitoring.CURRENT_PROC = []

Definition at line 387 of file esMonitoring.py.

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

Definition at line 458 of file esMonitoring.py.