Compare commits

...

3 commits

Author SHA1 Message Date
294a4e1273 Add argument parser 2023-11-17 16:25:51 +01:00
b54e31f4fd Lazy import of sqlalchemy 2023-11-17 16:24:00 +01:00
3d52b1b2c7 Format README 2023-11-17 16:20:57 +01:00
2 changed files with 28 additions and 3 deletions

View file

@ -9,9 +9,11 @@ Python script which querries the database for a list of jobids and produces a fi
Those files contain time-resolved power consumption data and are meant to be consumed by the utility in [monitoring/logs/scripts/plot_energy_logs.sh](../logs/README.md#scripts/plot_energy_logs.sh).
Requirements:
- Python module sqlalchemy `python -m pip install sqlalchemy`
- Python module sqlalchemy `python -m pip install sqlalchemy`
Usage:
```bash
ssh monitoring
./get_detailed_power.py 234556 767869.hawk-pbs5

View file

@ -1,15 +1,36 @@
import sqlalchemy as db
import numpy as np
from collections import OrderedDict
import os.path
def parse_arguments():
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('jobid', type=parse_jobid,
# nargs='+',
help='Job ID such as "2260215" or "226015.hawk-pbs5"')
return parser.parse_args()
def parse_jobid(s):
import re
hawkpbs = r'.hawk-pbs5'
jobid = re.sub(hawkpbs, '', s)
if not jobid.isdigit():
raise argparse.ArgumentTypeError(f'invalid job ID "{s}"')
return jobid
def init_db():
import sqlalchemy as db
_verbose = False #True
engine = db.create_engine('postgresql://hpc@hawk-monitor4:5432/coe_mon', echo=_verbose)
conn = engine.connect()
return conn
def init_query(jobid, interval):
import sqlalchemy as db
query_string = """with job as (
select job_id, starttime, endtime, nodes from jobs where job_id='{jobid}.hawk-pbs5'
),
@ -148,8 +169,10 @@ class Power:
if __name__ == "__main__":
args = parse_arguments()
conn = init_db()
jobid = "2260215"
jobid = args.jobid
interval = 5
query = init_query(jobid, interval)