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="Kill/restart the child process if it doesn't out the required string.")
 

Function Documentation

def esMonitoring.create_fifo ( )

Definition at line 242 of file esMonitoring.py.

References log().

Referenced by launch_monitoring().

243 def create_fifo():
244  prefix = "/tmp"
245  if os.path.isdir("/tmp/dqm_monitoring"):
246  prefix = "/tmp/dqm_monitoring"
247 
248  base = ".es_monitoring_pid%08d" % os.getpid()
249  fn = os.path.join(prefix, base)
250 
251  if os.path.exists(fn):
252  os.unlink(fn)
253 
254  os.mkfifo(fn, 0600)
255  if not os.path.exists(fn):
256  log("Failed to create fifo file: %s" % fn)
257  sys.exit(-1)
258 
259  atexit.register(os.unlink, fn)
260  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 318 of file esMonitoring.py.

319 def handle_signal(signum, frame):
320  for proc in CURRENT_PROC:
321  proc.send_signal(signum)
def esMonitoring.launch_monitoring (   args)

Definition at line 262 of file esMonitoring.py.

References create_fifo(), and log().

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

list esMonitoring.CURRENT_PROC = []

Definition at line 261 of file esMonitoring.py.

tuple esMonitoring.parser = argparse.ArgumentParser(description="Kill/restart the child process if it doesn't out the required string.")

Definition at line 323 of file esMonitoring.py.