This commit is contained in:
2020-05-25 16:57:48 +00:00
parent 5b5cdd653f
commit e7b705174a

View File

@@ -5,6 +5,7 @@ using System.Diagnostics;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using AyaNova.Util; using AyaNova.Util;
using AyaNova.Models; using AyaNova.Models;
using Microsoft.EntityFrameworkCore;
@@ -16,6 +17,7 @@ namespace AyaNova.Biz
internal static class CoreJobMetricsSnapshot internal static class CoreJobMetricsSnapshot
{ {
private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("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 Process _process = Process.GetCurrentProcess();
private static TimeSpan _oldCPUTime = TimeSpan.Zero; private static TimeSpan _oldCPUTime = TimeSpan.Zero;
@@ -34,8 +36,8 @@ namespace AyaNova.Biz
public static async Task DoJobAsync(AyContext ct) public static async Task DoJobAsync(AyContext ct)
{ {
//https://github.com/sebastienros/memoryleak/blob/master/src/MemoryLeak/MemoryLeak/Controllers/DiagnosticsController.cs //https://github.com/sebastienros/memoryleak/blob/master/src/MemoryLeak/MemoryLeak/Controllers/DiagnosticsController.cs
// //DATA TYPES .net to postgres map // //DATA TYPES .net to postgres map
//http://www.npgsql.org/doc/types/basic.html //http://www.npgsql.org/doc/types/basic.html
//Gather stats, output to database but only every minute or more //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 // The number of generation 2 collections
var Gen2 = GC.CollectionCount(2);//integer var Gen2 = GC.CollectionCount(2);//integer
var CPU=_cpu;// double precision var CPU = _cpu;// double precision
//write to db //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.MetricMM.AddAsync(mm);
await ct.SaveChangesAsync(); 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)) 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.FileCountGauge, mtag, UtilFilesInfo.FileCountWithChildren);
// metrics.Measure.Gauge.SetValue(MetricsRegistry.FileSizeGauge, mtag, UtilFilesInfo.SizeWithChildren); // 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;
} }