Compare commits

...

6 commits

2 changed files with 25 additions and 15 deletions

View file

@ -16,6 +16,9 @@ Requirements:
```bash
ssh monitoring
./get_detailed_power.py --help
./get_detailed_power.py 2335001 7678069.hawk-pbs5
Created file detailed_power.2335001.hawk-pbs5.100000-1000004.csv
Created file detailed_power.7678069.hawk-pbs5.2432345-423423.csv

View file

@ -4,16 +4,18 @@ from collections import OrderedDict
import os.path
def parse_arguments():
def parse_arguments(args):
parser = argparse.ArgumentParser(
description='Produce detailed power usage data for a list of jobids.')
parser.add_argument('-v', '--verbose', action='store_true',
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,
nargs='+',
help='Job ID such as "2260215" or "2260215.hawk-pbs5"')
return parser.parse_args()
return parser.parse_args(args)
def parse_jobid(s):
import re
@ -25,11 +27,12 @@ def parse_jobid(s):
class Power:
def __init__(self, nodes):
def __init__(self, nodes, interval=-1):
self.nodes = nodes
self.epochs = OrderedDict()
self.first_ts = None
self.last_ts = None
self.interval = interval
@classmethod
def from_list(cls, data):
@ -59,7 +62,10 @@ class Power:
if not all_list:
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):
"""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.body())
except IOError:
print("Error: could not write to file ", filename)
print("Error: could not write to file ", fname)
fname = None
return fname
def set_interval(self, interval):
self.interval = interval
def insert_epoch(self, ts, values):
self.epochs[ts] = values
if not self.first_ts:
@ -95,12 +104,11 @@ class Power:
def body(self):
_body = ""
for epoch in self.epochs.items():
_body += Power.pretty_print(self.summarize_epoch(epoch))
_body += self.pretty_print(self.summarize_epoch(epoch))
return _body
@staticmethod
def summarize_time(ts):
return ts, -1
def summarize_time(self, ts):
return ts, self.interval
@staticmethod
def summarize_values(val):
@ -111,11 +119,10 @@ class Power:
median = np.median(values)
return head, avg, median, min, max, stddev
@staticmethod
def summarize_epoch(epoch):
def summarize_epoch(self, epoch):
ts, values = epoch
return Power.summarize_time(ts) \
+ Power.summarize_values(values)
return self.summarize_time(ts) \
+ self.summarize_values(values)
# + values
@staticmethod
@ -204,8 +211,8 @@ class App:
if __name__ == "__main__":
config = parse_arguments()
config.interval = 5
import sys
config = parse_arguments(sys.argv[1:])
main = App(config)
main.run_all()