From 4b4a0c812129f7ae90477bda890a65360db3e860 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 3 Jun 2020 00:12:32 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- .../Controllers/ServerMetricsController.cs | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ee6f9a8a..d4a0659f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -49,7 +49,7 @@ "AYANOVA_USE_URLS": "http://*:7575;", "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", - "AYANOVA_SERVER_TEST_MODE":"true", + "AYANOVA_SERVER_TEST_MODE":"false", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL":"huge", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7", "AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\" diff --git a/server/AyaNova/Controllers/ServerMetricsController.cs b/server/AyaNova/Controllers/ServerMetricsController.cs index faec555c..4922b88f 100644 --- a/server/AyaNova/Controllers/ServerMetricsController.cs +++ b/server/AyaNova/Controllers/ServerMetricsController.cs @@ -33,6 +33,7 @@ namespace AyaNova.Api.Controllers private readonly ApiServerState serverState; private const int DEFAULT_MAX_RECORDS = 400; private const long MB = (1024 * 1024); + private const long KB = 1024; /// @@ -198,6 +199,8 @@ namespace AyaNova.Api.Controllers maxRecords ??= DEFAULT_MAX_RECORDS; + + //############ DB SIZE TIME SERIES MB List DBMetrics = new List(); //touniversal is because the parameters are converted to local time here //but then sent to the query as local time as well and not universal time which is what it should be @@ -205,15 +208,14 @@ namespace AyaNova.Api.Controllers var dsDBTotalSize = DBMetrics.Select(z => new Tuple(z.t.ToOADate(), z.DBTotalSize)).ToList(); dsDBTotalSize = Util.DataUtil.LargestTriangleThreeBuckets(dsDBTotalSize, (int)maxRecords) as List>; - //table distribution, top 10 + + + //############# TOP TABLES KB + List TopTables = new List(); using (var command = ct.Database.GetDbConnection().CreateCommand()) { - /* - pg_table_size(table_name) AS table_size, - pg_indexes_size(table_name) AS indexes_size, - */ - var cmd=@"SELECT + var cmd = @"SELECT table_name, pg_total_relation_size(table_name) AS total_size FROM ( @@ -223,9 +225,7 @@ namespace AyaNova.Api.Controllers ) AS all_tables ORDER BY total_size DESC"; command.CommandText = cmd; - - - + ct.Database.OpenConnection(); using (var dr = command.ExecuteReader()) { @@ -235,10 +235,10 @@ namespace AyaNova.Api.Controllers { long tableSize = dr.GetInt64(1); string tableName = dr.GetString(0); - tableName=tableName.Replace("\"","").Replace("public.a",""); + tableName = tableName.Replace("\"", "").Replace("public.a", ""); if (tableSize > 0) { - tableSize = tableSize / MB; + tableSize = tableSize / KB; } TopTables.Add(new MetricNameLongValue() { name = tableName, value = tableSize }); } @@ -247,8 +247,8 @@ namespace AyaNova.Api.Controllers } } - //trim out tables less than 1mb (the math above sets anything less than 1mb to zero) - TopTables = TopTables.Where(z => z.value > 0).OrderByDescending(z => z.value).ToList(); + //trim out tables less than 1kb (the math above sets anything less than 1kb to zero) + TopTables = TopTables.Where(z => z.value > 48).ToList();//NOTE: empty tables seem to all be 48kb so that's why this is here long DBTotalSize = 0; using (var command = ct.Database.GetDbConnection().CreateCommand()) @@ -259,7 +259,7 @@ namespace AyaNova.Api.Controllers { if (dr.HasRows) { - DBTotalSize = dr.Read() ? (dr.GetInt64(0) / MB) : 0; + DBTotalSize = dr.Read() ? (dr.GetInt64(0) / KB) : 0; } ct.Database.CloseConnection(); } @@ -274,7 +274,7 @@ namespace AyaNova.Api.Controllers var ret = new { - TopTables = TopTables, + TopTables = TopTables.OrderByDescending(z => z.value).ToList(), totalSize = dsDBTotalSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray() };