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

◆ __init__()

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
29  self.make_report_timer = 30
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, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ defaults()

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 = int(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 

◆ make_id()

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

◆ make_report()

def esMonitoring.ElasticReport.make_report (   self)

Definition at line 120 of file esMonitoring.py.

References DMRplotter.DMRplotter.args, tier0.Tier0Error.args, esMonitoring.ElasticReport.args, FrontierCondition_GT_autoExpress_cfi.Tier0Error.args, upload_popcon.HTTPError.args, conddb_version_mgr.conddb_tool.args, uploadConditions.HTTPError.args, o2olib.O2OTool.args, 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 

◆ try_update()

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 

◆ update_doc()

def esMonitoring.ElasticReport.update_doc (   self,
  keys 
)

◆ update_doc_recursive()

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 

◆ update_mem_status()

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, esMonitoring.str, nano_mu_digi_cff.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") dct = { key: f.read().strip() }
113  f.close()
114 
115  self.update_doc({ 'extra': { 'mem_info': dct } })
116  except:
117  pass
118 

◆ update_ps_status()

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, submitPVValidationJobs.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 

Member Data Documentation

◆ args

esMonitoring.ElasticReport.args

Definition at line 31 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_report().

◆ doc

◆ id_format

esMonitoring.ElasticReport.id_format

Definition at line 40 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.make_id().

◆ last_make_report

esMonitoring.ElasticReport.last_make_report

◆ make_report_timer

esMonitoring.ElasticReport.make_report_timer

Definition at line 29 of file esMonitoring.py.

Referenced by esMonitoring.ElasticReport.try_update().

◆ seq

esMonitoring.ElasticReport.seq

Definition at line 30 of file esMonitoring.py.