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

References log().

Referenced by launch_monitoring().

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

339 def handle_signal(signum, frame):
340  for proc in CURRENT_PROC:
341  proc.send_signal(signum)
def esMonitoring.launch_monitoring (   args)

Definition at line 282 of file esMonitoring.py.

References create_fifo(), and log().

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

list esMonitoring.CURRENT_PROC = []

Definition at line 281 of file esMonitoring.py.

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

Definition at line 343 of file esMonitoring.py.