CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes
esMonitoring.ElasticReport Class Reference
Inheritance diagram for esMonitoring.ElasticReport:

Public Member Functions

def __init__
 
def defaults
 
def flush
 
def make_id
 
def make_report
 
def try_update
 
def update_doc
 
def update_doc_recursive
 
def update_from_json
 
def update_ps_status
 
def update_stderr
 
def write
 

Public Attributes

 args
 
 doc
 
 id_format
 
 last_make_report
 
 make_report_timer
 
 s_history
 
 s_json
 
 s_path
 
 seq
 

Detailed Description

Definition at line 18 of file esMonitoring.py.

Constructor & Destructor Documentation

def esMonitoring.ElasticReport.__init__ (   self,
  pid,
  history,
  json,
  args 
)

Definition at line 19 of file esMonitoring.py.

19 
20  def __init__(self, pid, history, json, args):
21  self.s_history = history
22  self.s_json = json
23  self.s_path = "/tmp/dqm_monitoring/"
24 
25  self.last_make_report = None
27  self.seq = 0
28  self.args = args
29 
30  self.doc = {
31  "pid": pid,
32  "hostname": socket.gethostname(),
33  "sequence": self.seq,
34  "cmdline": args.pargs,
35  }
36 
37  self.defaults()

Member Function Documentation

def esMonitoring.ElasticReport.defaults (   self)

Definition at line 38 of file esMonitoring.py.

38 
39  def defaults(self):
40  self.id_format = u"%(type)s-run%(run)06d-host%(hostname)s-pid%(pid)06d"
41  self.doc["type"] = "dqm-source-state"
42  self.doc["run"] = 0
43 
44  # figure out the tag
45  c = self.doc["cmdline"]
46  for l in c:
47  if l.endswith(".py"):
48  t = os.path.basename(l)
49  t = t.replace(".py", "")
50  t = t.replace("_cfg", "")
51  self.doc["tag"] = t
52 
53  pr = l.split("=")
54  if len(pr) > 1 and pr[0] == "runNumber" and pr[1].isdigit():
55  run = long(pr[1])
56  self.doc["run"] = run
57 
58  self.make_id()
def esMonitoring.ElasticReport.flush (   self)

Definition at line 152 of file esMonitoring.py.

References esMonitoring.ElasticReport.try_update().

153  def flush(self):
154  self.try_update()
def esMonitoring.ElasticReport.make_id (   self)

Definition at line 59 of file esMonitoring.py.

References esMonitoring.ElasticReport.doc, and esMonitoring.ElasticReport.id_format.

Referenced by esMonitoring.ElasticReport.make_report().

59 
60  def make_id(self):
61  id = self.id_format % self.doc
62  self.doc["_id"] = id
63  return id
def esMonitoring.ElasticReport.make_report (   self)

Definition at line 108 of file esMonitoring.py.

References esMonitoring.ElasticReport.doc, esMonitoring.ElasticReport.last_make_report, esMonitoring.ElasticReport.make_id(), esMonitoring.ElasticReport.s_path, esMonitoring.ElasticReport.update_from_json(), esMonitoring.ElasticReport.update_ps_status(), and esMonitoring.ElasticReport.update_stderr().

Referenced by esMonitoring.ElasticReport.try_update().

109  def make_report(self):
110  self.last_make_report = time.time()
111  self.doc["report_timestamp"] = time.time()
112  self.update_from_json()
113  self.make_id()
114 
115  if not os.path.isdir(self.s_path):
116  # don't make a report if the directory is not available
117  return
118 
119  self.update_ps_status()
120  self.update_stderr()
121 
122  fn_id = self.doc["_id"] + ".jsn"
123 
124  if args.debug:
125  tm = "%.06f+" % time.time()
126  fn_id = tm + fn_id
127 
128  fn = os.path.join(self.s_path, fn_id)
129  fn_tmp = os.path.join(self.s_path, fn_id + ".tmp")
130 
131  with open(fn_tmp, "w") as f:
132  json.dump(self.doc, f, indent=True)
133 
134  os.rename(fn_tmp, fn)
def esMonitoring.ElasticReport.try_update (   self)

Definition at line 135 of file esMonitoring.py.

References esMonitoring.ElasticReport.last_make_report, esMonitoring.ElasticReport.make_report(), fff_deleter.FileDeleter.make_report(), esMonitoring.ElasticReport.make_report_timer, and esMonitoring.ElasticReport.s_json.

Referenced by esMonitoring.ElasticReport.flush(), and esMonitoring.ElasticReport.write().

136  def try_update(self):
137  # first time
138  if self.last_make_report is None:
139  return self.make_report()
140 
141  # is json stream has updates
142  if self.s_json and self.s_json.have_docs():
143  return self.make_report()
144 
145  now = time.time()
146  delta = now - self.last_make_report
147  if delta > self.make_report_timer:
148  return self.make_report()
def esMonitoring.ElasticReport.update_doc (   self,
  keys 
)

Definition at line 74 of file esMonitoring.py.

References esMonitoring.ElasticReport.doc, and esMonitoring.ElasticReport.update_doc_recursive().

Referenced by esMonitoring.ElasticReport.update_ps_status(), and esMonitoring.ElasticReport.update_stderr().

74 
75  def update_doc(self, keys):
76  self.update_doc_recursive(self.doc, keys)
def esMonitoring.ElasticReport.update_doc_recursive (   self,
  old_obj,
  new_obj 
)

Definition at line 64 of file esMonitoring.py.

References esMonitoring.ElasticReport.update_doc_recursive().

Referenced by esMonitoring.ElasticReport.update_doc(), esMonitoring.ElasticReport.update_doc_recursive(), and esMonitoring.ElasticReport.update_from_json().

64 
65  def update_doc_recursive(self, old_obj, new_obj):
66  for key, value in new_obj.items():
67  if (old_obj.has_key(key) and
68  isinstance(value, dict) and
69  isinstance(old_obj[key], dict)):
70 
71  self.update_doc_recursive(old_obj[key], value)
72  else:
73  old_obj[key] = value
def esMonitoring.ElasticReport.update_from_json (   self)

Definition at line 77 of file esMonitoring.py.

References esMonitoring.ElasticReport.doc, and esMonitoring.ElasticReport.update_doc_recursive().

Referenced by esMonitoring.ElasticReport.make_report().

77 
78  def update_from_json(self):
79  while self.s_json.have_docs():
80  doc = self.s_json.get_doc()
81 
82  # convert some values to integers
83  for k in ["pid", "run", "lumi"]:
84  if doc.has_key(k):
85  doc[k] = int(doc[k])
86 
87  self.update_doc_recursive(self.doc, doc)
def esMonitoring.ElasticReport.update_ps_status (   self)

Definition at line 88 of file esMonitoring.py.

References esMonitoring.ElasticReport.doc, split, and esMonitoring.ElasticReport.update_doc().

Referenced by esMonitoring.ElasticReport.make_report().

88 
89  def update_ps_status(self):
90  try:
91  pid = int(self.doc["pid"])
92  fn = "/proc/%d/status" % pid
93  f = open(fn, "r")
94  d = {}
95  for line in f:
96  k, v = line.strip().split(":", 1)
97  d[k.strip()] = v.strip()
98  f.close()
99 
100  self.update_doc({ 'extra': { 'ps_info': d } })
101  except:
102  pass
double split
Definition: MVATrainer.cc:139
def esMonitoring.ElasticReport.update_stderr (   self)

Definition at line 103 of file esMonitoring.py.

References esMonitoring.ElasticReport.s_history, and esMonitoring.ElasticReport.update_doc().

Referenced by esMonitoring.ElasticReport.make_report().

104  def update_stderr(self):
105  if self.s_history:
106  txt = self.s_history.read()
107  self.update_doc({ 'extra': { 'stdlog': txt } })
def esMonitoring.ElasticReport.write (   self,
  rbuf 
)

Definition at line 149 of file esMonitoring.py.

References esMonitoring.ElasticReport.try_update().

Referenced by pkg.AbstractPkg.generate().

150  def write(self, rbuf):
151  self.try_update()

Member Data Documentation

esMonitoring.ElasticReport.args

Definition at line 27 of file esMonitoring.py.

esMonitoring.ElasticReport.doc

Definition at line 29 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_id(), esMonitoring.ElasticReport.make_report(), esMonitoring.ElasticReport.update_doc(), esMonitoring.ElasticReport.update_from_json(), and esMonitoring.ElasticReport.update_ps_status().

esMonitoring.ElasticReport.id_format

Definition at line 39 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_id().

esMonitoring.ElasticReport.last_make_report

Definition at line 24 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_report(), and esMonitoring.ElasticReport.try_update().

esMonitoring.ElasticReport.make_report_timer

Definition at line 25 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.try_update().

esMonitoring.ElasticReport.s_history

Definition at line 20 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.update_stderr().

esMonitoring.ElasticReport.s_json

Definition at line 21 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.try_update().

esMonitoring.ElasticReport.s_path

Definition at line 22 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_report().

esMonitoring.ElasticReport.seq

Definition at line 26 of file esMonitoring.py.