CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 make_id
 
def make_report
 
def try_update
 
def update_doc
 
def update_doc_recursive
 
def update_mem_status
 
def update_ps_status
 

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 
28  def __init__(self, args):
29  self.last_make_report = None
31  self.seq = 0
32  self.args = args
33 
34  self.doc = {
35  "hostname": socket.gethostname(),
36  "sequence": self.seq,
37  "cmdline": args.pargs,
38  }

Member Function Documentation

def esMonitoring.ElasticReport.defaults (   self)

Definition at line 39 of file esMonitoring.py.

39 
40  def defaults(self):
41  self.id_format = u"%(type)s-run%(run)06d-host%(hostname)s-pid%(pid)06d"
42  self.doc["type"] = "dqm-source-state"
43  self.doc["run"] = 0
44 
45  # figure out the tag
46  c = self.doc["cmdline"]
47  for l in c:
48  if l.endswith(".py"):
49  t = os.path.basename(l)
50  t = t.replace(".py", "")
51  t = t.replace("_cfg", "")
52  self.doc["tag"] = t
53 
54  pr = l.split("=")
55  if len(pr) > 1 and pr[0] == "runNumber" and pr[1].isdigit():
56  run = int(pr[1])
57  self.doc["run"] = run
58 
59  self.make_id()
60 
61  #if os.environ.has_key("GZIP_LOG"):
62  # self.doc["stdlog_gzip"] = os.environ["GZIP_LOG"]
63 
64  try:
65  self.doc["stdout_fn"] = os.readlink("/proc/self/fd/1")
66  self.doc["stderr_fn"] = os.readlink("/proc/self/fd/2")
67  except:
68  pass
69 
70  self.update_doc({ "extra": {
71  "environ": dict(os.environ)
72  }})
def esMonitoring.ElasticReport.make_id (   self)

Definition at line 73 of file esMonitoring.py.

References nanoaod::MergeableCounterTable::SingleColumn< T >.doc, esMonitoring.ElasticReport.doc, nanoaod::MergeableCounterTable::VectorColumn< T >.doc, nanoaod::FlatTable::Column.doc, and esMonitoring.ElasticReport.id_format.

Referenced by esMonitoring.ElasticReport.make_report().

73 
74  def make_id(self):
75  id = self.id_format % self.doc
76  self.doc["_id"] = id
77  return id
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().

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

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

Definition at line 88 of file esMonitoring.py.

References nanoaod::MergeableCounterTable::SingleColumn< T >.doc, esMonitoring.ElasticReport.doc, nanoaod::MergeableCounterTable::VectorColumn< T >.doc, nanoaod::FlatTable::Column.doc, and esMonitoring.ElasticReport.update_doc_recursive().

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

88 
89  def update_doc(self, keys):
90  self.update_doc_recursive(self.doc, 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 
79  def update_doc_recursive(self, old_obj, new_obj):
80  for key, value in new_obj.items():
81  if (key in old_obj and
82  isinstance(value, dict) and
83  isinstance(old_obj[key], dict)):
84 
85  self.update_doc_recursive(old_obj[key], value)
86  else:
87  old_obj[key] = value
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, str, digitizers_cfi.strip, and esMonitoring.ElasticReport.update_doc().

Referenced by esMonitoring.ElasticReport.make_report().

107  def update_mem_status(self):
108  try:
109  key = str(time.time())
110 
111  pid = int(self.doc["pid"])
112  fn = "/proc/%d/statm" % pid
113  f = open(fn, "r")
114  dct = { key: f.read().strip() }
115  f.close()
116 
117  self.update_doc({ 'extra': { 'mem_info': dct } })
118  except:
119  pass
#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, submitPVValidationJobs.split(), and esMonitoring.ElasticReport.update_doc().

Referenced by esMonitoring.ElasticReport.make_report().

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

Member Data Documentation

esMonitoring.ElasticReport.args

Definition at line 31 of file esMonitoring.py.

esMonitoring.ElasticReport.doc

Definition at line 33 of file esMonitoring.py.

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

esMonitoring.ElasticReport.id_format

Definition at line 40 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_id().

esMonitoring.ElasticReport.last_make_report

Definition at line 28 of file esMonitoring.py.

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

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.