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

References log().

Referenced by launch_monitoring().

268 def create_fifo():
269  prefix = "/tmp"
270  if os.path.isdir("/tmp/dqm_monitoring"):
271  prefix = "/tmp/dqm_monitoring"
272 
273  base = ".es_monitoring_pid%08d" % os.getpid()
274  fn = os.path.join(prefix, base)
275 
276  if os.path.exists(fn):
277  os.unlink(fn)
278 
279  os.mkfifo(fn, 0600)
280  if not os.path.exists(fn):
281  log("Failed to create fifo file: %s" % fn)
282  sys.exit(-1)
283 
284  atexit.register(os.unlink, fn)
285  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 343 of file esMonitoring.py.

344 def handle_signal(signum, frame):
345  for proc in CURRENT_PROC:
346  proc.send_signal(signum)
def esMonitoring.launch_monitoring (   args)

Definition at line 287 of file esMonitoring.py.

References create_fifo(), and log().

288 def launch_monitoring(args):
289  fifo = create_fifo()
290  mon_fd = os.open(fifo, os.O_RDONLY | os.O_NONBLOCK)
291 
292  def preexec():
293  # this should only be open on a parent
294  os.close(mon_fd)
295 
296  # open fifo once (hack)
297  # so there is *always* at least one writter
298  # which closes with the executable
299  os.open(fifo, os.O_WRONLY)
300 
301  try:
302  # ensure the child dies if we are SIGKILLED
303  import ctypes
304  libc = ctypes.CDLL("libc.so.6")
305  PR_SET_PDEATHSIG = 1
306  libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
307  except:
308  log("Failed to setup PR_SET_PDEATHSIG.")
309  pass
310 
311  env = os.environ
312  env["DQMMON_UPDATE_PIPE"] = fifo
313 
314  p = subprocess.Popen(args.pargs, preexec_fn=preexec, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
315  CURRENT_PROC.append(p)
316 
317  mon_file = os.fdopen(mon_fd)
318  s_hist = History()
319  s_json = JsonInput()
320  report_sink = ElasticReport(pid=p.pid, history=s_hist, json=s_json, args=args)
321 
322  stdout_cap = DescriptorCapture(p.stdout, write_files=[sys.stdout, s_hist, report_sink, ], )
323  stderr_cap = DescriptorCapture(p.stderr, write_files=[sys.stderr, s_hist, report_sink, ], )
324  stdmon_cap = DescriptorCapture(mon_file, write_files=[s_json, report_sink, ],)
325 
326  fs = [stdout_cap, stderr_cap, stdmon_cap]
327  try:
328  DescriptorCapture.event_loop(fs, timeout=1000, timeout_call=report_sink.flush)
329  except select.error, e:
330  # we have this on ctrl+c
331  # just terminate the child
332  log("Select error (we will terminate): " + str(e))
333  p.terminate()
334 
335  # at this point the program is dead
336  r = p.wait()
337  CURRENT_PROC.remove(p)
338 
339  report_sink.update_doc({ "exit_code": r })
340  report_sink.make_report()
341 
342  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 352 of file esMonitoring.py.

list esMonitoring.CURRENT_PROC = []

Definition at line 286 of file esMonitoring.py.

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

Definition at line 348 of file esMonitoring.py.