This commit is contained in:
2020-06-03 00:12:32 +00:00
parent c239dd6b15
commit 4b4a0c8121
2 changed files with 16 additions and 16 deletions

2
.vscode/launch.json vendored
View File

@@ -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\\"

View File

@@ -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;
/// <summary>
@@ -198,6 +199,8 @@ namespace AyaNova.Api.Controllers
maxRecords ??= DEFAULT_MAX_RECORDS;
//############ DB SIZE TIME SERIES MB
List<MetricDD> DBMetrics = new List<MetricDD>();
//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<double, double>(z.t.ToOADate(), z.DBTotalSize)).ToList();
dsDBTotalSize = Util.DataUtil.LargestTriangleThreeBuckets(dsDBTotalSize, (int)maxRecords) as List<Tuple<double, double>>;
//table distribution, top 10
//############# TOP TABLES KB
List<MetricNameLongValue> TopTables = new List<MetricNameLongValue>();
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()
};