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
 
 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 
24  self.last_make_report = None
26  self.seq = 0
27  self.args = args
28 
29  self.doc = {
30  "pid": pid,
31  "hostname": socket.gethostname(),
32  "sequence": self.seq,
33  "cmdline": args.pargs,
34  }
35 
36  self.defaults()

Member Function Documentation

def esMonitoring.ElasticReport.defaults (   self)

Definition at line 37 of file esMonitoring.py.

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

Definition at line 147 of file esMonitoring.py.

References esMonitoring.ElasticReport.try_update().

148  def flush(self):
149  self.try_update()
def esMonitoring.ElasticReport.make_id (   self)

Definition at line 58 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

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

Definition at line 107 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.try_update().

108  def make_report(self):
109  self.last_make_report = time.time()
110  self.doc["report_timestamp"] = time.time()
111 
112  self.update_from_json()
113  self.make_id()
114  self.update_ps_status()
115  self.update_stderr()
116 
117  fn_id = self.doc["_id"] + ".jsn"
118 
119  if args.debug:
120  tm = "%.06f+" % time.time()
121  fn_id = tm + fn_id
122 
123  fn = os.path.join("/tmp/dqm_monitoring/", fn_id)
124  fn_tmp = os.path.join("/tmp/dqm_monitoring/", fn_id + ".tmp")
125 
126  with open(fn_tmp, "w") as f:
127  json.dump(self.doc, f, indent=True)
128 
129  os.rename(fn_tmp, fn)
def esMonitoring.ElasticReport.try_update (   self)

Definition at line 130 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().

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

Definition at line 73 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().

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

Definition at line 63 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().

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

Definition at line 76 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

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

Definition at line 87 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

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

Definition at line 102 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

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

Definition at line 144 of file esMonitoring.py.

References esMonitoring.ElasticReport.try_update().

Referenced by pkg.AbstractPkg.generate().

145  def write(self, rbuf):
146  self.try_update()

Member Data Documentation

esMonitoring.ElasticReport.args

Definition at line 26 of file esMonitoring.py.

esMonitoring.ElasticReport.doc

Definition at line 28 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 38 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_id().

esMonitoring.ElasticReport.last_make_report

Definition at line 23 of file esMonitoring.py.

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

esMonitoring.ElasticReport.make_report_timer

Definition at line 24 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.seq

Definition at line 25 of file esMonitoring.py.