Metric.py
Go to the documentation of this file.
1 class Metric():
2  """
3  A class for holding metrics
4  """
5  def __init__(self):
6  #print "metrc: --- Initalise metric"
7  self.return_code = None
8  self.run = False
9  self.input_events = None
10  self.used_events = None
11  self.user_cpu = None
12  self.system_cpu = None
13  self.peak_memory = None
14  self.memory = None
15  self.output_name = None
16  self.output_size = None
17  self.output_events = None
18  self.file_size_ana = None
19  self.db_usage = None
20  self.advanced = False
21  self.memory_percent = None
22  self.cpu_percent = None
23  self.read_bytes = None
24  self.write_bytes = None
25  self.u_cpu_times = None
26  self.s_cpu_times = None
27  self.rss_memory = None
28  self.vms_memory = None
29  self.open_files = None
30  self.n_open_files = None
31  self.connections = None
32  self.n_connections = None
33  self.sample_times = None
34 
36  self.advanced = True
37  self.memory_percent = []
38  self.cpu_percent = []
39  self.read_bytes = []
40  self.write_bytes = []
41  self.u_cpu_times = []
42  self.s_cpu_times = []
43  self.rss_memory = []
44  self.vms_memory = []
45  self.open_files = []
46  self.connections = []
47 
48  def fill_advanced_metrics(self, p):
49  # These sometimes throws access denied errors
50  try: self.memory_percent.append(p.get_memory_percent())
51  except: self.memory_percent.append(self.memory_percent[-1])
52 
53  try:
54  cpu = p.get_cpu_percent()
55  if cpu > 100.: cpu = 100.
56  self.cpu_percent.append( cpu )
57  except: self.cpu_percent.append( self.cpu_percent[-1])
58 
59  # try: self.read_bytes.append( p.get_io_counters().read_bytes)
60  # except: self.read_bytes.append( self.read_bytes[-1])
61 
62  # try: self.write_bytes.append( p.get_io_counters().write_bytes)
63  # except: self.write_bytes.append( self.write_bytes[-1])
64 
65  try: self.u_cpu_times.append( p.get_cpu_times().user)
66  except: self.u_cpu_times.append( self.u_cpu_times[-1])
67 
68  try: self.s_cpu_times.append( p.get_cpu_times().system)
69  except: self.s_cpu_times.append( self.s_cpu_times[-1])
70 
71  # try: self.rss_memory.append( p.get_memory_info().rss)
72  # except: self.rss_memory.append( self.rss_memory[-1])
73 
74  try: self.vms_memory.append( p.get_memory_info().vms)
75  except: self.vms_memory.append( self.vms_memory[-1])
76 
77  # try: self.open_files.append( p.get_open_files())
78  # except: self.open_files.append( self.open_files[-1])
79 
80  # try: self.connections.append( p.get_connections())
81  # except: self.connections.append( self.connections[-1])
82 
83  def refresh(self):
84  self.n_connections = [len(c) for c in self.connections]
85  self.n_open_files = [len(c) for c in self.open_files]
86 
87  def __repr__(self):
88  _repr = "metrc: --- Metric\n"
89  _repr += "metrc: return_code: %s\n"%(repr(self.return_code))
90  _repr += "metrc: run: %s\n"%(repr(self.run))
91  _repr += "metrc: input_events: %s\n"%(repr(self.input_events))
92  _repr += "metrc: used_events: %s\n"%(repr(self.used_events))
93  _repr += "metrc: user_cpu: %s\n"%(repr(self.user_cpu))
94  _repr += "metrc: system_cpu: %s\n"%(repr(self.system_cpu))
95  _repr += "metrc: peak_memory: %s\n"%(repr(self.peak_memory))
96  _repr += "metrc: n_memory: %s\n"%(repr(len(self.memory)))
97  #_repr += "metrc: n_samples: %s\n"%(repr(len(self.sample_times)))
98  _repr += "metrc: output_name: %s\n"%(repr(self.output_name))
99  _repr += "metrc: output_events: %s\n"%(repr(self.output_events))
100  _repr += "metrc: output_size: %s\n"%(repr(self.output_size))
101  _repr += "metrc: db_usage: \n%s\n" %(repr(self.db_usage))
102  #_repr += "metrc: advanced: %s" %(repr(self.advanced))
103  return _repr
def __repr__(self)
Definition: Metric.py:87
def __init__(self)
Definition: Metric.py:5
def refresh(self)
Definition: Metric.py:83
def fill_advanced_metrics(self, p)
Definition: Metric.py:48
def enable_advanced_metrics(self)
Definition: Metric.py:35