From 4ec9b3216e19d66cc3cf342a592ff87039f39b1a Mon Sep 17 00:00:00 2001 From: Stephen Lien Harrell Date: Fri, 24 Jan 2025 14:42:25 -0500 Subject: [PATCH] Add update_metrics.py to run in the container --- hpcperfstats/analysis/gen/jid_table.py | 3 -- .../analysis/metrics/update_metrics.py | 34 ++----------------- services-conf/supervisord.conf | 12 +++++++ 3 files changed, 15 insertions(+), 34 deletions(-) diff --git a/hpcperfstats/analysis/gen/jid_table.py b/hpcperfstats/analysis/gen/jid_table.py index e6467b3..1cd9ce1 100644 --- a/hpcperfstats/analysis/gen/jid_table.py +++ b/hpcperfstats/analysis/gen/jid_table.py @@ -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 @@ -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 diff --git a/hpcperfstats/analysis/metrics/update_metrics.py b/hpcperfstats/analysis/metrics/update_metrics.py index 965e9c4..22b4fce 100755 --- a/hpcperfstats/analysis/metrics/update_metrics.py +++ b/hpcperfstats/analysis/metrics/update_metrics.py @@ -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 @@ -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 @@ -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) diff --git a/services-conf/supervisord.conf b/services-conf/supervisord.conf index 5399b76..92d3c50 100644 --- a/services-conf/supervisord.conf +++ b/services-conf/supervisord.conf @@ -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 +