Outline query string as class constant
This commit is contained in:
parent
41dab7a647
commit
ae00b04bbe
1 changed files with 22 additions and 19 deletions
|
@ -139,25 +139,8 @@ class Power:
|
|||
|
||||
|
||||
class MonitoringDB:
|
||||
def __init__(self, verbose):
|
||||
self.connection = self.init_db(verbose)
|
||||
|
||||
@staticmethod
|
||||
def init_db(verbose):
|
||||
import sqlalchemy as db
|
||||
_verbose = False #True
|
||||
engine = db.create_engine('postgresql://hpc@hawk-monitor4:5432/coe_mon', echo=verbose)
|
||||
connection = engine.connect()
|
||||
return connection
|
||||
|
||||
def close_db(self):
|
||||
return self.connection.close()
|
||||
|
||||
@staticmethod
|
||||
def build_query(jobid, interval):
|
||||
"""Query taken from https://kb.hlrs.de/monitoring/index.php/TimescaleDB_-_Query_Guidelines#Power_by_Job_Query"""
|
||||
import sqlalchemy as db
|
||||
query_string = """with _job as (
|
||||
QUERY_STRING_HAWK = """
|
||||
with _job as (
|
||||
select job_id, starttime, endtime, nodes from job where job_id='{jobid}.hawk-pbs5'
|
||||
),
|
||||
node_series as(
|
||||
|
@ -184,6 +167,26 @@ select a.time, a.value, ns.name from (
|
|||
group by time, cmcavg.series_id order by time desc) a
|
||||
inner join node_series ns on a.series_id::int = ns.series_id;
|
||||
"""
|
||||
|
||||
def __init__(self, verbose):
|
||||
self.connection = self.init_db(verbose)
|
||||
|
||||
@staticmethod
|
||||
def init_db(verbose):
|
||||
import sqlalchemy as db
|
||||
_verbose = False #True
|
||||
engine = db.create_engine('postgresql://hpc@hawk-monitor4:5432/coe_mon', echo=verbose)
|
||||
connection = engine.connect()
|
||||
return connection
|
||||
|
||||
def close_db(self):
|
||||
return self.connection.close()
|
||||
|
||||
@classmethod
|
||||
def build_query(cls, jobid, interval):
|
||||
"""Query taken from https://kb.hlrs.de/monitoring/index.php/TimescaleDB_-_Query_Guidelines#Power_by_Job_Query"""
|
||||
import sqlalchemy as db
|
||||
query_string = cls.QUERY_STRING_HAWK
|
||||
return db.text(query_string.format(jobid=jobid, interval=interval))
|
||||
|
||||
def db_to_list(self, jobid, interval):
|
||||
|
|
Loading…
Reference in a new issue