Merge branch 'pgsql-db'
This commit is contained in:
commit
1bb1e72c24
2 changed files with 25 additions and 15 deletions
|
@ -16,6 +16,9 @@ Requirements:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ssh monitoring
|
ssh monitoring
|
||||||
|
|
||||||
|
./get_detailed_power.py --help
|
||||||
|
|
||||||
./get_detailed_power.py 2335001 7678069.hawk-pbs5
|
./get_detailed_power.py 2335001 7678069.hawk-pbs5
|
||||||
Created file detailed_power.2335001.hawk-pbs5.100000-1000004.csv
|
Created file detailed_power.2335001.hawk-pbs5.100000-1000004.csv
|
||||||
Created file detailed_power.7678069.hawk-pbs5.2432345-423423.csv
|
Created file detailed_power.7678069.hawk-pbs5.2432345-423423.csv
|
||||||
|
|
|
@ -4,16 +4,18 @@ from collections import OrderedDict
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments(args):
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Produce detailed power usage data for a list of jobids.')
|
description='Produce detailed power usage data for a list of jobids.')
|
||||||
parser.add_argument('-v', '--verbose', action='store_true',
|
parser.add_argument('-v', '--verbose', action='store_true',
|
||||||
help='Show database querries, etc.')
|
help='Show database querries, etc.')
|
||||||
|
parser.add_argument('-t', '--interval', action='store', type=float, default=5.0,
|
||||||
|
help="Interval between power values in seconds")
|
||||||
parser.add_argument('jobid', type=parse_jobid,
|
parser.add_argument('jobid', type=parse_jobid,
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='Job ID such as "2260215" or "2260215.hawk-pbs5"')
|
help='Job ID such as "2260215" or "2260215.hawk-pbs5"')
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args(args)
|
||||||
|
|
||||||
def parse_jobid(s):
|
def parse_jobid(s):
|
||||||
import re
|
import re
|
||||||
|
@ -25,11 +27,12 @@ def parse_jobid(s):
|
||||||
|
|
||||||
|
|
||||||
class Power:
|
class Power:
|
||||||
def __init__(self, nodes):
|
def __init__(self, nodes, interval=-1):
|
||||||
self.nodes = nodes
|
self.nodes = nodes
|
||||||
self.epochs = OrderedDict()
|
self.epochs = OrderedDict()
|
||||||
self.first_ts = None
|
self.first_ts = None
|
||||||
self.last_ts = None
|
self.last_ts = None
|
||||||
|
self.interval = interval
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_list(cls, data):
|
def from_list(cls, data):
|
||||||
|
@ -59,7 +62,10 @@ class Power:
|
||||||
if not all_list:
|
if not all_list:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
return Power.from_list(all_list)
|
power = cls.from_list(all_list)
|
||||||
|
power.set_interval(interval*1000) # milliseconds
|
||||||
|
|
||||||
|
return power
|
||||||
|
|
||||||
def to_file(self, jobid):
|
def to_file(self, jobid):
|
||||||
"""Dumps power data to file. Returns filename is succesfull and None if unsucessfull."""
|
"""Dumps power data to file. Returns filename is succesfull and None if unsucessfull."""
|
||||||
|
@ -73,11 +79,14 @@ class Power:
|
||||||
f.write(self.header())
|
f.write(self.header())
|
||||||
f.write(self.body())
|
f.write(self.body())
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Error: could not write to file ", filename)
|
print("Error: could not write to file ", fname)
|
||||||
fname = None
|
fname = None
|
||||||
|
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
|
def set_interval(self, interval):
|
||||||
|
self.interval = interval
|
||||||
|
|
||||||
def insert_epoch(self, ts, values):
|
def insert_epoch(self, ts, values):
|
||||||
self.epochs[ts] = values
|
self.epochs[ts] = values
|
||||||
if not self.first_ts:
|
if not self.first_ts:
|
||||||
|
@ -95,12 +104,11 @@ class Power:
|
||||||
def body(self):
|
def body(self):
|
||||||
_body = ""
|
_body = ""
|
||||||
for epoch in self.epochs.items():
|
for epoch in self.epochs.items():
|
||||||
_body += Power.pretty_print(self.summarize_epoch(epoch))
|
_body += self.pretty_print(self.summarize_epoch(epoch))
|
||||||
return _body
|
return _body
|
||||||
|
|
||||||
@staticmethod
|
def summarize_time(self, ts):
|
||||||
def summarize_time(ts):
|
return ts, self.interval
|
||||||
return ts, -1
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def summarize_values(val):
|
def summarize_values(val):
|
||||||
|
@ -111,11 +119,10 @@ class Power:
|
||||||
median = np.median(values)
|
median = np.median(values)
|
||||||
return head, avg, median, min, max, stddev
|
return head, avg, median, min, max, stddev
|
||||||
|
|
||||||
@staticmethod
|
def summarize_epoch(self, epoch):
|
||||||
def summarize_epoch(epoch):
|
|
||||||
ts, values = epoch
|
ts, values = epoch
|
||||||
return Power.summarize_time(ts) \
|
return self.summarize_time(ts) \
|
||||||
+ Power.summarize_values(values)
|
+ self.summarize_values(values)
|
||||||
# + values
|
# + values
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -204,8 +211,8 @@ class App:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
config = parse_arguments()
|
import sys
|
||||||
config.interval = 5
|
config = parse_arguments(sys.argv[1:])
|
||||||
|
|
||||||
main = App(config)
|
main = App(config)
|
||||||
main.run_all()
|
main.run_all()
|
||||||
|
|
Loading…
Reference in a new issue