diff --git a/schema/grant/grafana.sql b/schema/grant/grafana.sql index 1ab909d..72710a8 100644 --- a/schema/grant/grafana.sql +++ b/schema/grant/grafana.sql @@ -5,4 +5,6 @@ GRANT SELECT ON metrics TO :role_name; -- crashing when it runs out of memory GRANT SELECT ON agg_instance_load TO :role_name; +GRANT SELECT ON agg_instance_load_long TO :role_name; + GRANT SELECT ON agg_instance_pods TO :role_name; \ No newline at end of file diff --git a/schema/query/history-load.sql b/schema/query/history-load.sql index 6a26cdf..1f0def2 100644 --- a/schema/query/history-load.sql +++ b/schema/query/history-load.sql @@ -1,10 +1,44 @@ SELECT - a.bucket AS time, - a.avg_load, - a.max_load, - REGEXP_REPLACE(l.labels->>'instance', '(.+):[0-9]+', '\1') AS instance -FROM - agg_instance_load AS a -JOIN - metric_labels AS l -ON l.lid = a.lid; \ No newline at end of file + l.labels->>'instance' AS metric, + s.time, + s.value +FROM (( + SELECT + lid, + bucket AS time, + max_load AS value + FROM + agg_instance_load_long + WHERE bucket < NOW() - INTERVAL '1 day' + ORDER BY lid, bucket +) UNION ALL ( + SELECT + lid, + bucket AS time, + max_load AS value + FROM + agg_instance_load + WHERE bucket > NOW() - INTERVAL '1 day' + ORDER BY lid, bucket +) UNION ALL ( + SELECT + lid, + "tg" AS "time", + MAX("value") AS "value" + FROM ( + SELECT + lid, + time_bucket(INTERVAL '1 minute', time) AS "tg", + value + FROM metrics + WHERE + time > NOW() - INTERVAL '15 minutes' + AND name = 'node_load1' + AND value != 'NaN' + ) t + GROUP BY lid, time + ORDER BY lid, time +)) AS s +JOIN metric_labels AS l +ON l.lid = s.lid +ORDER BY s.time, s.lid; \ No newline at end of file diff --git a/schema/views/instance-load.sql b/schema/views/instance-load.sql index f4207aa..b15cadd 100644 --- a/schema/views/instance-load.sql +++ b/schema/views/instance-load.sql @@ -2,8 +2,8 @@ CREATE VIEW agg_instance_load WITH ( timescaledb.continuous, timescaledb.refresh_interval = '5m', - timescaledb.refresh_lag = '5m') -AS SELECT + timescaledb.refresh_lag = '5m' +) AS SELECT lid, time_bucket('5 minutes', time) "bucket", AVG(value) AS "avg_load", @@ -11,4 +11,20 @@ AS SELECT FROM metric_samples WHERE name = 'node_load1' -GROUP BY lid, bucket; \ No newline at end of file +GROUP BY lid, bucket; + + +CREATE VIEW agg_instance_load_long +WITH ( + timescaledb.continuous, + timescaledb.refresh_interval = '1h', + timescaledb.refresh_lag = '1h' +) AS SELECT + lid, + time_bucket('1 hour', time) AS "bucket", + AVG(value) AS "avg_load", + MAX(value) AS "max_load" +FROM metric_samples +WHERE + name = 'node_load1' +GROUP BY lid, bucket;