This commit is contained in:
2020-06-01 23:20:17 +00:00
parent c266848774
commit 843599e452

View File

@@ -206,12 +206,52 @@ namespace AyaNova.Api.Controllers
dsDBTotalSize = Util.DataUtil.LargestTriangleThreeBuckets(dsDBTotalSize, (int)maxRecords) as List<Tuple<double, double>>;
//table distribution, top 10
List<MetricNameSize> TopTen = new List<MetricNameSize>();
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; }
}
//----------
}