Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 15f60a8c authored by Simon Delamare's avatar Simon Delamare
Browse files

db: add api.get_job_metrics function

parent 0311fac8
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ chunk_interval_hour: 6
chunk_compress_hour: 24
request_timeout_min: 5
archive_path: ''
jobmetrics_requests_path: ''
"""
config = pyonf(config, mandatory_opts=["kwollect_password"])
globals().update(config)
......@@ -479,6 +480,36 @@ END;
$$ LANGUAGE 'plpgsql';
"""
sql(cmd)
cmd = """
DROP FUNCTION IF EXISTS api.get_job_metrics;
CREATE OR REPLACE FUNCTION api.get_job_metrics(job_id INTEGER DEFAULT NULL)
RETURNS JSON
AS $$
DECLARE
j JSON;
BEGIN
SELECT to_json(s) INTO j FROM (
WITH jobmetrics AS (
SELECT * FROM api.get_metrics(job_id => job_id, as_rate => 'auto')
)
SELECT job_id AS job_id, * FROM
(SELECT AGE(COALESCE(stop_time, NOW()), start_time) AS job_duration_time FROM nodetime_by_job WHERE nodetime_by_job.job_id = $1 GROUP BY nodetime_by_job.job_id, start_time, stop_time) sdefault"""
if jobmetrics_requests_path:
for i, req in enumerate(open(jobmetrics_requests_path).readlines()):
cmd += f",\n ({req}) s{i}"
cmd += """
) s;
RETURN j;
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE;
"""
sql(cmd)
print("Database setup done.")
print("")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment