Skip to content

Commit

Permalink
Add update_metrics.py to run in the container
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlienharrell committed Jan 24, 2025
1 parent f89d812 commit 4ec9b32
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
3 changes: 0 additions & 3 deletions hpcperfstats/analysis/gen/jid_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os,sys,time
# Append your local repository path here:
# sys.path.append("/home/sg99/hpcperfstats")
import psycopg2
import hpcperfstats.conf_parser as cfg
from hpcperfstats.analysis.gen.utils import read_sql
Expand All @@ -10,7 +8,6 @@ class jid_table:
def __init__(self, jid):

CONNECTION = cfg.get_db_connection_string()
print(CONNECTION)
print("Initializing table for job {0}".format(jid))

self.jid = jid
Expand Down
34 changes: 3 additions & 31 deletions hpcperfstats/analysis/metrics/update_metrics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python
import os,sys, pwd
# Append your local repository path here:
# sys.path.append("/home/sg99/hpcperfstats")
import os, sys, pwd, time
from datetime import timedelta, datetime
import psycopg2

Expand All @@ -15,32 +13,6 @@
import hpcperfstats.conf_parser as cfg
from hpcperfstats.progress import progress

CONNECTION = cfg.get_db_connection_string()

query_create_metric_table = """CREATE TABLE IF NOT EXISTS metrics_data (
id SERIAL PRIMARY KEY,
jid VARCHAR(32),
type VARCHAR(32),
metric VARCHAR(32),
units VARCHAR(16),
value real,
FOREIGN KEY(jid) REFERENCES job_data(jid),
UNIQUE (jid, type, metric)
);"""
query_create_jobindex = "CREATE INDEX ON metrics_data (jid);"


def create_metrics_table(reset = False):
conn = psycopg2.connect(CONNECTION)
with conn.cursor() as cur:
if reset:
cur.execute("DROP TABLE IF EXISTS metrics_data CASCADE;")
cur.execute(query_create_metric_table)
cur.execute(query_create_jobindex)
conn.commit()
conn.close()


def update_metrics(date, rerun = False):

min_time = 300
Expand Down Expand Up @@ -75,9 +47,9 @@ def update_metrics(date, rerun = False):
print("###Date Range of metrics to update: {0} -> {1}####".format(startdate, enddate))
#################################################################

create_metrics_table(reset = False)

date = startdate
while date <= enddate:
update_metrics(date, rerun = False)
date += timedelta(days=1)

time.sleep(3600)
12 changes: 12 additions & 0 deletions services-conf/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ stderr_redirect=true
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0

[program:update_metrics]
command=/usr/local/bin/python3 /home/hpcperfstats/hpcperfstats/analysis/metrics/update_metrics.py
user=hpcperfstats
autorestart=true
startretries=20
stdout_redirect=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_redirect=true
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0

0 comments on commit 4ec9b32

Please sign in to comment.