This commit is contained in:
@@ -178,6 +178,49 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get database related metrics for time period specified
|
||||
/// </summary>
|
||||
/// <param name="tsStart">Start timestamp UTC</param>
|
||||
/// <param name="tsEnd">End timestamp UTC</param>
|
||||
/// <param name="maxRecords">Optional maximum records to return (downsampled). There is a 400 record maximum fixed default</param>
|
||||
/// <returns>Snapshot of metrics</returns>
|
||||
[HttpGet("db")]
|
||||
public async Task<IActionResult> GetDBMetrics([FromQuery, Required] DateTime? tsStart, [FromQuery, Required] DateTime? tsEnd, [FromQuery] int? maxRecords)
|
||||
{
|
||||
//Note: the date and times are nullable and required so that the regular modelstate code kicks in to ensure they are present
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Metrics))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
maxRecords ??= DEFAULT_MAX_RECORDS;
|
||||
|
||||
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
|
||||
DBMetrics = await ct.MetricDD.AsNoTracking().Where(z => z.t >= ((DateTime)tsStart).ToUniversalTime() && z.t <= ((DateTime)tsEnd).ToUniversalTime()).OrderBy(z => z.t).ToListAsync();
|
||||
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
|
||||
|
||||
|
||||
var ret = new
|
||||
{
|
||||
|
||||
totalSize = dsDBTotalSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray()
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace AyaNova.Biz
|
||||
_lastMMSnapshot = now;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
@@ -157,8 +157,25 @@ namespace AyaNova.Biz
|
||||
var UtilityFilesAvailableSpace = FileUtil.UtilityFilesDriveAvailableSpace();
|
||||
var AttachmentFilesAvailableSpace = FileUtil.AttachmentFilesDriveAvailableSpace();
|
||||
|
||||
|
||||
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
//DB total size
|
||||
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();
|
||||
}
|
||||
}
|
||||
//write to db
|
||||
MetricDD dd = new MetricDD()
|
||||
{
|
||||
@@ -167,7 +184,8 @@ namespace AyaNova.Biz
|
||||
AttachmentFilesAvailableSpace = AttachmentFilesAvailableSpace,
|
||||
UtilityFileSize = UtilFilesInfo.SizeWithChildren,
|
||||
UtilityFileCount = UtilFilesInfo.FileCountWithChildren,
|
||||
UtilityFilesAvailableSpace = UtilityFilesAvailableSpace
|
||||
UtilityFilesAvailableSpace = UtilityFilesAvailableSpace,
|
||||
DBTotalSize = DBTotalSize
|
||||
};
|
||||
ct.MetricDD.Add(dd);
|
||||
ct.SaveChanges();
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace AyaNova.Models
|
||||
public long UtilityFileCount { get; set; }
|
||||
public long UtilityFilesAvailableSpace { get; set; }
|
||||
|
||||
public long DBTotalSize { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace AyaNova.Util
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
||||
private const int DESIRED_SCHEMA_LEVEL = 11;
|
||||
|
||||
internal const long EXPECTED_COLUMN_COUNT = 327;
|
||||
internal const long EXPECTED_COLUMN_COUNT = 328;
|
||||
internal const long EXPECTED_INDEX_COUNT = 134;
|
||||
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
||||
@@ -252,7 +252,7 @@ namespace AyaNova.Util
|
||||
//One hour metrics
|
||||
await ExecQueryAsync("CREATE TABLE ametrichh (t timestamp not null, test bigint)");
|
||||
//One day metrics
|
||||
await ExecQueryAsync("CREATE TABLE ametricdd (t timestamp not null, attachmentfilesize bigint, attachmentfilecount bigint, attachmentfilesavailablespace bigint, utilityfilesize bigint, utilityfilecount bigint, utilityfilesavailablespace bigint)");
|
||||
await ExecQueryAsync("CREATE TABLE ametricdd (t timestamp not null, dbtotalsize bigint, attachmentfilesize bigint, attachmentfilecount bigint, attachmentfilesavailablespace bigint, utilityfilesize bigint, utilityfilecount bigint, utilityfilesavailablespace bigint)");
|
||||
|
||||
|
||||
//SEARCH TABLES
|
||||
|
||||
Reference in New Issue
Block a user