This commit is contained in:
@@ -206,11 +206,11 @@ namespace AyaNova.Api.Controllers
|
|||||||
dsDBTotalSize = Util.DataUtil.LargestTriangleThreeBuckets(dsDBTotalSize, (int)maxRecords) as List<Tuple<double, double>>;
|
dsDBTotalSize = Util.DataUtil.LargestTriangleThreeBuckets(dsDBTotalSize, (int)maxRecords) as List<Tuple<double, double>>;
|
||||||
|
|
||||||
//table distribution, top 10
|
//table distribution, top 10
|
||||||
List<MetricNameSize> TopTen = new List<MetricNameSize>();
|
List<MetricNameLongValue> TopTables = new List<MetricNameLongValue>();
|
||||||
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
||||||
{
|
{
|
||||||
//top 10 tables by size
|
//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;";
|
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;";
|
||||||
ct.Database.OpenConnection();
|
ct.Database.OpenConnection();
|
||||||
using (var dr = command.ExecuteReader())
|
using (var dr = command.ExecuteReader())
|
||||||
{
|
{
|
||||||
@@ -218,13 +218,21 @@ namespace AyaNova.Api.Controllers
|
|||||||
{
|
{
|
||||||
while (dr.Read())
|
while (dr.Read())
|
||||||
{
|
{
|
||||||
TopTen.Add(new MetricNameSize() { name = dr.GetString(0), size = dr.GetInt64(1) });
|
long tableSize = dr.GetInt64(1);
|
||||||
|
if (tableSize > 0)
|
||||||
|
{
|
||||||
|
tableSize = tableSize / MB;
|
||||||
|
}
|
||||||
|
TopTables.Add(new MetricNameLongValue() { name = dr.GetString(0), value = tableSize });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ct.Database.CloseConnection();
|
ct.Database.CloseConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//trim out tables we don't want here
|
||||||
|
TopTables = TopTables.Where(z => z.value > 0).OrderByDescending(z => z.value).ToList();
|
||||||
|
|
||||||
long DBTotalSize = 0;
|
long DBTotalSize = 0;
|
||||||
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
||||||
{
|
{
|
||||||
@@ -234,25 +242,23 @@ namespace AyaNova.Api.Controllers
|
|||||||
{
|
{
|
||||||
if (dr.HasRows)
|
if (dr.HasRows)
|
||||||
{
|
{
|
||||||
DBTotalSize = dr.Read() ? dr.GetInt64(0) : 0;
|
DBTotalSize = dr.Read() ? (dr.GetInt64(0) / MB) : 0;
|
||||||
}
|
}
|
||||||
ct.Database.CloseConnection();
|
ct.Database.CloseConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long ttSize = 0;
|
long ttSize = 0;
|
||||||
foreach (MetricNameSize tt in TopTen)
|
foreach (MetricNameLongValue tt in TopTables)
|
||||||
{
|
{
|
||||||
ttSize += tt.size;
|
ttSize += tt.value;
|
||||||
}
|
}
|
||||||
TopTen.Add(new MetricNameSize() { name = "other", size = DBTotalSize - ttSize });
|
TopTables.Add(new MetricNameLongValue() { name = "other", value = DBTotalSize - ttSize });
|
||||||
|
|
||||||
var ret = new
|
var ret = new
|
||||||
{
|
{
|
||||||
|
TopTables = TopTables,
|
||||||
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
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -300,10 +306,10 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MetricNameSize
|
public class MetricNameLongValue
|
||||||
{
|
{
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public long size { get; set; }
|
public long value { get; set; }
|
||||||
}
|
}
|
||||||
//----------
|
//----------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user