CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
esMonitoring.ElasticReport Class Reference
Inheritance diagram for esMonitoring.ElasticReport:

Public Member Functions

def __init__ (self, args)
 
def defaults (self)
 
def make_id (self)
 
def make_report (self)
 
def try_update (self)
 
def update_doc (self, keys)
 
def update_doc_recursive (self, old_obj, new_obj)
 
def update_mem_status (self)
 
def update_ps_status (self)
 

Public Attributes

 args
 
 doc
 
 id_format
 
 last_make_report
 
 make_report_timer
 
 seq
 

Detailed Description

Definition at line 26 of file esMonitoring.py.

Constructor & Destructor Documentation

def esMonitoring.ElasticReport.__init__ (   self,
  args 
)

Definition at line 27 of file esMonitoring.py.

27  def __init__(self, args):
28  self.last_make_report = None
30  self.seq = 0
31  self.args = args
32 
33  self.doc = {
34  "hostname": socket.gethostname(),
35  "sequence": self.seq,
36  "cmdline": args.pargs,
37  }
38 
def __init__(self, args)
Definition: esMonitoring.py:27

Member Function Documentation

def esMonitoring.ElasticReport.defaults (   self)

Definition at line 39 of file esMonitoring.py.

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 
60  #if os.environ.has_key("GZIP_LOG"):
61  # self.doc["stdlog_gzip"] = os.environ["GZIP_LOG"]
62 
63  try:
64  self.doc["stdout_fn"] = os.readlink("/proc/self/fd/1")
65  self.doc["stderr_fn"] = os.readlink("/proc/self/fd/2")
66  except:
67  pass
68 
69  self.update_doc({ "extra": {
70  "environ": dict(os.environ)
71  }})
72 
def update_doc(self, keys)
Definition: esMonitoring.py:88
def esMonitoring.ElasticReport.make_id (   self)
def esMonitoring.ElasticReport.make_report (   self)

Definition at line 120 of file esMonitoring.py.

References nanoaod::MergeableCounterTable::SingleColumn< T >.doc, esMonitoring.ElasticReport.doc, nanoaod::MergeableCounterTable::VectorColumn< T >.doc, nanoaod::FlatTable::Column.doc, esMonitoring.ElasticReport.last_make_report, esMonitoring.log(), esMonitoring.ElasticReport.make_id(), esMonitoring.ElasticReport.update_mem_status(), and esMonitoring.ElasticReport.update_ps_status().

Referenced by esMonitoring.ElasticReport.try_update().

120  def make_report(self):
121  self.last_make_report = time.time()
122  self.doc["report_timestamp"] = time.time()
123  self.make_id()
124 
125  m_path = self.args.path
126 
127  if not os.path.isdir(m_path):
128  if self.args.debug:
129  log("File not written, because report directory does not exist: %s." % m_path)
130  # don't make a report if the directory is not available
131  return
132 
133  self.update_ps_status()
134  self.update_mem_status()
135 
136  fn_id = self.doc["_id"] + ".jsn"
137 
138  fn = os.path.join(m_path, fn_id)
139  fn_tmp = os.path.join(m_path, fn_id + ".tmp")
140 
141  with open(fn_tmp, "w") as f:
142  json.dump(self.doc, f, indent=True, cls=JsonEncoder)
143 
144  os.rename(fn_tmp, fn)
145 
146  if self.args.debug:
147  log("File %s written." % fn)
148 
def esMonitoring.ElasticReport.try_update (   self)

Definition at line 149 of file esMonitoring.py.

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

149  def try_update(self):
150  # first time
151  if self.last_make_report is None:
152  return self.make_report()
153 
154  now = time.time()
155  delta = now - self.last_make_report
156  if delta > self.make_report_timer:
157  return self.make_report()
158 
def esMonitoring.ElasticReport.update_doc (   self,
  keys 
)
def esMonitoring.ElasticReport.update_doc_recursive (   self,
  old_obj,
  new_obj 
)

Definition at line 78 of file esMonitoring.py.

References esMonitoring.ElasticReport.update_doc_recursive().

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

78  def update_doc_recursive(self, old_obj, new_obj):
79  for key, value in new_obj.items():
80  if (key in old_obj and
81  isinstance(value, dict) and
82  isinstance(old_obj[key], dict)):
83 
84  self.update_doc_recursive(old_obj[key], value)
85  else:
86  old_obj[key] = value
87 
def update_doc_recursive(self, old_obj, new_obj)
Definition: esMonitoring.py:78
def esMonitoring.ElasticReport.update_mem_status (   self)

Definition at line 106 of file esMonitoring.py.

References nanoaod::MergeableCounterTable::SingleColumn< T >.doc, esMonitoring.ElasticReport.doc, nanoaod::MergeableCounterTable::VectorColumn< T >.doc, nanoaod::FlatTable::Column.doc, createfilelist.int, str, digitizers_cfi.strip, and esMonitoring.ElasticReport.update_doc().

Referenced by esMonitoring.ElasticReport.make_report().

106  def update_mem_status(self):
107  try:
108  key = str(time.time())
109 
110  pid = int(self.doc["pid"])
111  fn = "/proc/%d/statm" % pid
112  f = open(fn, "r")
113  dct = { key: f.read().strip() }
114  f.close()
115 
116  self.update_doc({ 'extra': { 'mem_info': dct } })
117  except:
118  pass
119 
def update_doc(self, keys)
Definition: esMonitoring.py:88
#define str(s)
def esMonitoring.ElasticReport.update_ps_status (   self)

Definition at line 91 of file esMonitoring.py.

References nanoaod::MergeableCounterTable::SingleColumn< T >.doc, esMonitoring.ElasticReport.doc, nanoaod::MergeableCounterTable::VectorColumn< T >.doc, nanoaod::FlatTable::Column.doc, createfilelist.int, split, and esMonitoring.ElasticReport.update_doc().

Referenced by esMonitoring.ElasticReport.make_report().

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

Member Data Documentation

esMonitoring.ElasticReport.args

Definition at line 31 of file esMonitoring.py.

esMonitoring.ElasticReport.doc
esMonitoring.ElasticReport.id_format

Definition at line 40 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_id().

esMonitoring.ElasticReport.last_make_report
esMonitoring.ElasticReport.make_report_timer

Definition at line 29 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.try_update().

esMonitoring.ElasticReport.seq

Definition at line 30 of file esMonitoring.py.