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 find_stdout
 
def flush
 
def make_id
 
def make_report
 
def try_update
 
def update_doc
 
def update_doc_recursive
 
def update_from_json
 
def update_mem_status
 
def update_ps_status
 
def update_stdlog
 
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()
59  self.find_stdout()
def esMonitoring.ElasticReport.find_stdout (   self)

Definition at line 60 of file esMonitoring.py.

References esMonitoring.ElasticReport.doc.

60 
61  def find_stdout(self):
62  try:
63  self.doc["stdout_fn"] = os.readlink("/proc/self/fd/1")
64  self.doc["stderr_fn"] = os.readlink("/proc/self/fd/2")
65  except:
66  pass
67 
def esMonitoring.ElasticReport.flush (   self)

Definition at line 177 of file esMonitoring.py.

References esMonitoring.ElasticReport.try_update().

178  def flush(self):
179  self.try_update()
def esMonitoring.ElasticReport.make_id (   self)

Definition at line 68 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

68 
69  def make_id(self):
70  id = self.id_format % self.doc
71  self.doc["_id"] = id
72  return id
def esMonitoring.ElasticReport.make_report (   self)

Definition at line 131 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_mem_status(), esMonitoring.ElasticReport.update_ps_status(), and esMonitoring.ElasticReport.update_stdlog().

Referenced by esMonitoring.ElasticReport.try_update().

132  def make_report(self):
133  self.last_make_report = time.time()
134  self.doc["report_timestamp"] = time.time()
135  self.update_from_json()
136  self.make_id()
137 
138  if not os.path.isdir(self.s_path):
139  # don't make a report if the directory is not available
140  return
141 
142  self.update_ps_status()
143  self.update_mem_status()
144  self.update_stdlog()
145 
146  fn_id = self.doc["_id"] + ".jsn"
147 
148  if args.debug:
149  tm = "%.06f+" % time.time()
150  fn_id = tm + fn_id
151 
152  fn = os.path.join(self.s_path, fn_id)
153  fn_tmp = os.path.join(self.s_path, fn_id + ".tmp")
154 
155  with open(fn_tmp, "w") as f:
156  json.dump(self.doc, f, indent=True)
157 
158  os.rename(fn_tmp, fn)
def esMonitoring.ElasticReport.try_update (   self)

Definition at line 159 of file esMonitoring.py.

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

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

160  def try_update(self):
161  # first time
162  if self.last_make_report is None:
163  return self.make_report()
164 
165  # if json stream has updates
166  if self.s_json and self.s_json.have_docs():
167  # just apply them, it still goes through timer
168  self.update_from_json()
169 
170  now = time.time()
171  delta = now - self.last_make_report
172  if delta > self.make_report_timer:
173  return self.make_report()
def esMonitoring.ElasticReport.update_doc (   self,
  keys 
)

Definition at line 83 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.update_mem_status(), esMonitoring.ElasticReport.update_ps_status(), and esMonitoring.ElasticReport.update_stdlog().

83 
84  def update_doc(self, keys):
85  self.update_doc_recursive(self.doc, keys)
def esMonitoring.ElasticReport.update_doc_recursive (   self,
  old_obj,
  new_obj 
)

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

73 
74  def update_doc_recursive(self, old_obj, new_obj):
75  for key, value in new_obj.items():
76  if (old_obj.has_key(key) and
77  isinstance(value, dict) and
78  isinstance(old_obj[key], dict)):
79 
80  self.update_doc_recursive(old_obj[key], value)
81  else:
82  old_obj[key] = value
def esMonitoring.ElasticReport.update_from_json (   self)

Definition at line 86 of file esMonitoring.py.

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

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

86 
87  def update_from_json(self):
88  while self.s_json.have_docs():
89  doc = self.s_json.get_doc()
90 
91  # convert some values to integers
92  for k in ["pid", "run", "lumi"]:
93  if doc.has_key(k):
94  doc[k] = int(doc[k])
95 
96  self.update_doc_recursive(self.doc, doc)
def esMonitoring.ElasticReport.update_mem_status (   self)

Definition at line 112 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

113  def update_mem_status(self):
114  try:
115  key = str(time.time())
116 
117  pid = int(self.doc["pid"])
118  fn = "/proc/%d/statm" % pid
119  f = open(fn, "r")
120  dct = { key: f.read().strip() }
121  f.close()
122 
123  self.update_doc({ 'extra': { 'mem_info': dct } })
124  except:
125  pass
def esMonitoring.ElasticReport.update_ps_status (   self)

Definition at line 97 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

97 
98  def update_ps_status(self):
99  try:
100  pid = int(self.doc["pid"])
101  fn = "/proc/%d/status" % pid
102  f = open(fn, "r")
103  d = {}
104  for line in f:
105  k, v = line.strip().split(":", 1)
106  d[k.strip()] = v.strip()
107  f.close()
108 
109  self.update_doc({ 'extra': { 'ps_info': d } })
110  except:
111  pass
double split
Definition: MVATrainer.cc:139
def esMonitoring.ElasticReport.update_stdlog (   self)

Definition at line 126 of file esMonitoring.py.

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

Referenced by esMonitoring.ElasticReport.make_report().

127  def update_stdlog(self):
128  if self.s_history:
129  txt = self.s_history.read()
130  self.update_doc({ 'extra': { 'stdlog': txt } })
def esMonitoring.ElasticReport.write (   self,
  rbuf 
)

Definition at line 174 of file esMonitoring.py.

References esMonitoring.ElasticReport.try_update().

Referenced by pkg.AbstractPkg.generate().

175  def write(self, rbuf):
176  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.find_stdout(), esMonitoring.ElasticReport.make_id(), esMonitoring.ElasticReport.make_report(), esMonitoring.ElasticReport.update_doc(), esMonitoring.ElasticReport.update_from_json(), esMonitoring.ElasticReport.update_mem_status(), 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_stdlog().

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.