From 843599e452305fe2d10f28b11aa6a1585f64a5f9 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 1 Jun 2020 23:20:17 +0000 Subject: [PATCH] --- .../Controllers/ServerMetricsController.cs | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/server/AyaNova/Controllers/ServerMetricsController.cs b/server/AyaNova/Controllers/ServerMetricsController.cs index 2cb062c3..430a5b12 100644 --- a/server/AyaNova/Controllers/ServerMetricsController.cs +++ b/server/AyaNova/Controllers/ServerMetricsController.cs @@ -206,12 +206,52 @@ namespace AyaNova.Api.Controllers dsDBTotalSize = Util.DataUtil.LargestTriangleThreeBuckets(dsDBTotalSize, (int)maxRecords) as List>; //table distribution, top 10 - + List TopTen = new List(); + using (var command = ct.Database.GetDbConnection().CreateCommand()) + { + //top 10 tables by size + command.CommandText = @"SELECT relname AS ""table_name"", pg_table_size(C.oid) AS ""table_size"" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND nspname !~ '^pg_toast' AND relkind IN ('r') ORDER BY pg_table_size(C.oid) DESC LIMIT 10;"; + ct.Database.OpenConnection(); + using (var dr = command.ExecuteReader()) + { + if (dr.HasRows) + { + while (dr.Read()) + { + TopTen.Add(new MetricNameSize() { name = dr.GetString(0), size = dr.GetInt64(1) }); + } + } + ct.Database.CloseConnection(); + } + } + + long DBTotalSize = 0; + using (var command = ct.Database.GetDbConnection().CreateCommand()) + { + command.CommandText = "select pg_database_size(current_database());"; + ct.Database.OpenConnection(); + using (var dr = command.ExecuteReader()) + { + if (dr.HasRows) + { + DBTotalSize = dr.Read() ? dr.GetInt64(0) : 0; + } + ct.Database.CloseConnection(); + } + } + + long ttSize = 0; + foreach (MetricNameSize tt in TopTen) + { + ttSize += tt.size; + } + TopTen.Add(new MetricNameSize() { name = "other", size = DBTotalSize - ttSize }); var ret = new { - - totalSize = dsDBTotalSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray() + + totalSize = dsDBTotalSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(), + TopTen = TopTen }; @@ -259,6 +299,12 @@ namespace AyaNova.Api.Controllers } } + + public class MetricNameSize + { + public string name { get; set; } + public long size { get; set; } + } //---------- }