diff --git a/server/AyaNova/Controllers/ServerMetricsController.cs b/server/AyaNova/Controllers/ServerMetricsController.cs index c2401b7a..ee25d7c3 100644 --- a/server/AyaNova/Controllers/ServerMetricsController.cs +++ b/server/AyaNova/Controllers/ServerMetricsController.cs @@ -49,37 +49,37 @@ namespace AyaNova.Api.Controllers serverState = apiServerState; } -#if (DEBUG) - [HttpGet("collect")] - [AllowAnonymous] - public ActionResult GetCollect() - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); +// #if (DEBUG) +// [HttpGet("collect")] +// [AllowAnonymous] +// public ActionResult GetCollect() +// { +// GC.Collect(); +// GC.WaitForPendingFinalizers(); +// GC.Collect(); - return Ok(); - } +// return Ok(); +// } - [HttpGet("hammer")] - [AllowAnonymous] - public async Task GetHammer() - { - //test allocation and cleanup - for (int x = 0; x < 100000; x++) - { - AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext; - var v=await ct.Widget.Where(z=>z.Serial<100).ToListAsync(); - // int i = await ct.Database.ExecuteSqlRawAsync($"select * from aglobalbizsettings"); - } +// [HttpGet("hammer")] +// [AllowAnonymous] +// public async Task GetHammer() +// { +// //test allocation and cleanup +// for (int x = 0; x < 100000; x++) +// { +// AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext; +// var v=await ct.Widget.Where(z=>z.Serial<100).ToListAsync(); +// // int i = await ct.Database.ExecuteSqlRawAsync($"select * from aglobalbizsettings"); +// } - return Ok(); - } +// return Ok(); +// } -#endif +// #endif /// /// Get Memory and CPU server metrics for time period specified @@ -118,22 +118,10 @@ namespace AyaNova.Api.Controllers var dsPrivateBytes = MinuteMetrics.Select(z => new Tuple(z.t.ToOADate(), z.PrivateBytes)).ToList(); dsPrivateBytes = Util.DataUtil.LargestTriangleThreeBuckets(dsPrivateBytes, (int)maxRecords) as List>; - - var dsGen0 = MinuteMetrics.Select(z => new Tuple(z.t.ToOADate(), z.Gen0)).ToList(); - dsGen0 = Util.DataUtil.LargestTriangleThreeBuckets(dsGen0, (int)maxRecords) as List>; - - var dsGen1 = MinuteMetrics.Select(z => new Tuple(z.t.ToOADate(), z.Gen1)).ToList(); - dsGen1 = Util.DataUtil.LargestTriangleThreeBuckets(dsGen1, (int)maxRecords) as List>; - - var dsGen2 = MinuteMetrics.Select(z => new Tuple(z.t.ToOADate(), z.Gen2)).ToList(); - dsGen2 = Util.DataUtil.LargestTriangleThreeBuckets(dsGen2, (int)maxRecords) as List>; - + var ret = new { - cpu = dsCPU.Select(z => new MetricDouble(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(), - gen0 = dsGen0.Select(z => new MetricInt(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(), - gen1 = dsGen1.Select(z => new MetricInt(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(), - gen2 = dsGen2.Select(z => new MetricInt(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(), + cpu = dsCPU.Select(z => new MetricDouble(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(), allocated = dsAllocated.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(), workingSet = dsWorkingSet.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(), privateBytes = dsPrivateBytes.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray() diff --git a/server/AyaNova/generator/CoreJobMetricsSnapshot.cs b/server/AyaNova/generator/CoreJobMetricsSnapshot.cs index 298102f1..94d49ff5 100644 --- a/server/AyaNova/generator/CoreJobMetricsSnapshot.cs +++ b/server/AyaNova/generator/CoreJobMetricsSnapshot.cs @@ -20,20 +20,17 @@ namespace AyaNova.Biz private static Process _process = Process.GetCurrentProcess(); private static TimeSpan _oldCPUTime = TimeSpan.Zero; - private static DateTime _lastMMSnapshot = DateTime.UtcNow; - private static DateTime _lastHHSnapshot = DateTime.UtcNow; + private static DateTime _lastMMSnapshot = DateTime.UtcNow; private static DateTime _lastDDSnapshot = DateTime.UtcNow; // private static DateTime _lastRpsTime = DateTime.UtcNow; private static double _cpu = 0; #if(DEBUG) - private static TimeSpan tsOneMinute = new TimeSpan(0, 0, 10); - private static TimeSpan tsOneHour = new TimeSpan(0, 1, 0); - private static TimeSpan ts24Hours = new TimeSpan(0, 1, 0); + private static TimeSpan tsOneMinute = new TimeSpan(0, 1, 0); + private static TimeSpan ts24Hours = new TimeSpan(24, 0, 0); #else - private static TimeSpan tsOneMinute = new TimeSpan(0, 1, 0); - private static TimeSpan tsOneHour = new TimeSpan(1, 0, 0); + private static TimeSpan tsOneMinute = new TimeSpan(0, 1, 0); private static TimeSpan ts24Hours = new TimeSpan(24, 0, 0); #endif //////////////////////////////////////////////////////////////////////////////////////////////// @@ -71,15 +68,7 @@ namespace AyaNova.Biz // cannot be shared with other processes. var PrivateBytes = _process.PrivateMemorySize64;//bigint - // The number of generation 0 collections - var Gen0 = GC.CollectionCount(0);//integer - - // The number of generation 1 collections - var Gen1 = GC.CollectionCount(1);//integer - - // The number of generation 2 collections - var Gen2 = GC.CollectionCount(2);//integer - + //NOTE: CPU percentage is *our* process cpu percentage over timeframe of last captured avg //So it does *not* show the entire server cpu load, only for RAVEN. //Overall, server stats need to be captured / viewed independently (digital ocean control panel for example or windows task manager) @@ -93,59 +82,15 @@ namespace AyaNova.Biz using (AyContext ct = ServiceProviderProvider.DBContext) { //write to db - MetricMM mm = new MetricMM(Allocated, WorkingSet, PrivateBytes, Gen0, Gen1, Gen2, CPU); + MetricMM mm = new MetricMM(Allocated, WorkingSet, PrivateBytes, CPU); ct.MetricMM.Add(mm); ct.SaveChanges(); //System.Diagnostics.Debug.WriteLine("MM SAVED"); } _lastMMSnapshot = now; - - - } - ///////////////////////////////////////////// - //EVERY HOUR SNAPS - // - if (DateUtil.IsAfterDuration(_lastHHSnapshot, tsOneHour)) - { - var now = DateTime.UtcNow; - log.LogTrace("HH metrics snapshot"); - //RECORDS IN TABLE - // //Only do this once per hour - // log.LogTrace("Counting table records"); - - - // //Get a count of important tables in db - // List allTableNames = await DbUtil.GetAllTablenamesAsync(); - - // //Skip some tables as they are internal and / or only ever have one record - // List skipTableNames = new List(); - // skipTableNames.Add("alicense"); - // skipTableNames.Add("aschemaversion"); - - // foreach (string table in allTableNames) - // { - // if (!skipTableNames.Contains(table)) - // { - // //var tags = new MetricTags("TableTagKey", table); - // // metrics.Measure.Gauge.SetValue(MetricsRegistry.DBRecordsGauge, tags, await DbUtil.CountOfRecordsAsync(table)); - // } - // } - - - //JOB COUNTS (DEAD, RUNNING, COMPLETED, SLEEPING) - - // foreach (JobStatus stat in Enum.GetValues(typeof(JobStatus))) - // { - // // var jobtag = new MetricTags("JobStatus", stat.ToString()); - // // metrics.Measure.Gauge.SetValue(MetricsRegistry.JobsGauge, jobtag, await JobsBiz.GetCountForJobStatusAsync(ct, stat)); - // } - _lastHHSnapshot = now; - - } - - + ///////////////////////////////////////////// //ONCE A DAY SNAPS AND CLEANUP @@ -162,8 +107,6 @@ namespace AyaNova.Biz var UtilityFilesAvailableSpace = FileUtil.UtilityFilesDriveAvailableSpace(); var AttachmentFilesAvailableSpace = FileUtil.AttachmentFilesDriveAvailableSpace(); - - using (AyContext ct = ServiceProviderProvider.DBContext) { //DB total size @@ -204,7 +147,7 @@ namespace AyaNova.Biz DateTime ClearDate = DateTime.UtcNow - tsDataRetention; using (AyContext ct = ServiceProviderProvider.DBContext) { - // ct.Database.ExecuteSqlInterpolated($"delete from ametricmm where t < {ClearDate.ToUniversalTime()}"); + ct.Database.ExecuteSqlInterpolated($"delete from ametricmm where t < {ClearDate.ToUniversalTime()}"); } _lastDDSnapshot = now; } diff --git a/server/AyaNova/models/MetricMM.cs b/server/AyaNova/models/MetricMM.cs index a87d508c..8f437b1f 100644 --- a/server/AyaNova/models/MetricMM.cs +++ b/server/AyaNova/models/MetricMM.cs @@ -14,24 +14,18 @@ namespace AyaNova.Models public DateTime t { get; set; } public long Allocated { get; set; } public long WorkingSet { get; set; } - public long PrivateBytes { get; set; } - public int Gen0 { get; set; } - public int Gen1 { get; set; } - public int Gen2 { get; set; } + public long PrivateBytes { get; set; } public double CPU { get; set; } //ef core requires this public MetricMM() { } - public MetricMM(long allocated, long workingSet, long privateBytes, int gen0, int gen1, int gen2, double cpu) + public MetricMM(long allocated, long workingSet, long privateBytes, double cpu) { t = System.DateTime.UtcNow; Allocated = allocated; WorkingSet = workingSet; - PrivateBytes = privateBytes; - Gen0 = gen0; - Gen1 = gen1; - Gen2 = gen2; + PrivateBytes = privateBytes; CPU = cpu; } }//eoc diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index c7d9e94e..e7b8b367 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -248,9 +248,7 @@ namespace AyaNova.Util //METRICS TABLES //One minute metrics - await ExecQueryAsync("CREATE TABLE ametricmm (t timestamp not null, allocated bigint,workingset bigint,privatebytes bigint,gen0 integer,gen1 integer,gen2 integer,cpu double precision)"); - //One hour metrics - await ExecQueryAsync("CREATE TABLE ametrichh (t timestamp not null, test bigint)"); + await ExecQueryAsync("CREATE TABLE ametricmm (t timestamp not null, allocated bigint,workingset bigint,privatebytes bigint,cpu double precision)"); //One day metrics await ExecQueryAsync("CREATE TABLE ametricdd (t timestamp not null, dbtotalsize bigint, attachmentfilesize bigint, attachmentfilecount bigint, attachmentfilesavailablespace bigint, utilityfilesize bigint, utilityfilecount bigint, utilityfilesavailablespace bigint)");