From e7b705174a0858a5dbf283a43a219a007fa729a6 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 25 May 2020 16:57:48 +0000 Subject: [PATCH] --- .../generator/CoreJobMetricsSnapshot.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server/AyaNova/generator/CoreJobMetricsSnapshot.cs b/server/AyaNova/generator/CoreJobMetricsSnapshot.cs index 40bdffca..ace6fbdb 100644 --- a/server/AyaNova/generator/CoreJobMetricsSnapshot.cs +++ b/server/AyaNova/generator/CoreJobMetricsSnapshot.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using Microsoft.Extensions.Logging; using AyaNova.Util; using AyaNova.Models; +using Microsoft.EntityFrameworkCore; @@ -16,6 +17,7 @@ namespace AyaNova.Biz internal static class CoreJobMetricsSnapshot { private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("CoreJobMetricsSnapshot"); + private static TimeSpan tsDataRetention = new TimeSpan(396, 0, 0, 0, 0);//one year and one month approximately private static Process _process = Process.GetCurrentProcess(); private static TimeSpan _oldCPUTime = TimeSpan.Zero; @@ -34,8 +36,8 @@ namespace AyaNova.Biz public static async Task DoJobAsync(AyContext ct) { //https://github.com/sebastienros/memoryleak/blob/master/src/MemoryLeak/MemoryLeak/Controllers/DiagnosticsController.cs -// //DATA TYPES .net to postgres map - //http://www.npgsql.org/doc/types/basic.html + // //DATA TYPES .net to postgres map + //http://www.npgsql.org/doc/types/basic.html //Gather stats, output to database but only every minute or more /* @@ -190,13 +192,13 @@ from generate_series(1, 525600) s(i) // The number of generation 2 collections var Gen2 = GC.CollectionCount(2);//integer - var CPU=_cpu;// double precision + var CPU = _cpu;// double precision //write to db - MetricMM mm = new MetricMM(Allocated,WorkingSet,PrivateBytes,Gen0,Gen1,Gen2,CPU); + MetricMM mm = new MetricMM(Allocated, WorkingSet, PrivateBytes, Gen0, Gen1, Gen2, CPU); await ct.MetricMM.AddAsync(mm); await ct.SaveChangesAsync(); - + ///////////////////////////////////////////// @@ -243,7 +245,7 @@ from generate_series(1, 525600) s(i) ///////////////////////////////////////////// - //ONCE A DAY SNAPS + //ONCE A DAY SNAPS AND CLEANUP // if (DateUtil.IsAfterDuration(_lastSnapshot, ts24Hours)) { @@ -260,13 +262,18 @@ from generate_series(1, 525600) s(i) // metrics.Measure.Gauge.SetValue(MetricsRegistry.FileCountGauge, mtag, UtilFilesInfo.FileCountWithChildren); // metrics.Measure.Gauge.SetValue(MetricsRegistry.FileSizeGauge, mtag, UtilFilesInfo.SizeWithChildren); + ///////////////////////////////// + //CLEAR OLD ENTRIES + // + DateTime ClearAfter = DateTime.UtcNow - tsDataRetention; + await ct.Database.ExecuteSqlInterpolatedAsync($"delete from ametricmm where t > {ClearAfter}"); } - _lastSnapshot = now; + _lastSnapshot = now; }