From 6ff52227ef7a8f97cb7e430b8ae7c5e51e58a482 Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Wed, 22 Nov 2023 14:35:19 +0100 Subject: [PATCH 1/5] Decouple argument parser from sys.argv --- monitoring/db/scripts/get_detailed_power.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index 60b8232..fa2cf60 100644 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -4,7 +4,7 @@ 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', @@ -13,7 +13,7 @@ def parse_arguments(): 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 @@ -204,8 +204,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() From 4a2107d6df429c1df6af56dae53d03f8f06f6ad6 Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Wed, 22 Nov 2023 14:45:14 +0100 Subject: [PATCH 2/5] Add argument for interval and report in output --- monitoring/db/scripts/get_detailed_power.py | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index fa2cf60..2461f0b 100644 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -9,6 +9,8 @@ def parse_arguments(args): 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"') @@ -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.""" @@ -78,6 +84,9 @@ class Power: 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: @@ -98,9 +107,8 @@ class Power: _body += Power.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 From e6b291daa79e3c58059d83f63939459d3c833d34 Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Wed, 22 Nov 2023 14:46:25 +0100 Subject: [PATCH 3/5] Call method through self --- monitoring/db/scripts/get_detailed_power.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index 2461f0b..adbc90d 100644 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -104,7 +104,7 @@ 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 def summarize_time(self, ts): From f6991fb57b21081c48ce6289b12f55fd51f06b0f Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Wed, 22 Nov 2023 14:46:51 +0100 Subject: [PATCH 4/5] Fix unknown symbol --- monitoring/db/scripts/get_detailed_power.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index adbc90d..12387d6 100644 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -79,7 +79,7 @@ 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 From df11a511ce5f7558c1b6d1f7df8d4d0c0c19df7d Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Wed, 22 Nov 2023 14:55:44 +0100 Subject: [PATCH 5/5] Update README --- monitoring/db/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monitoring/db/README.md b/monitoring/db/README.md index d3978f7..f22836a 100644 --- a/monitoring/db/README.md +++ b/monitoring/db/README.md @@ -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