This commit is contained in:
2020-05-29 14:59:04 +00:00
parent eca81a068d
commit 3540baa0ec
2 changed files with 80 additions and 70 deletions

View File

@@ -219,18 +219,26 @@ namespace AyaNova.Api.Controllers
var dsAttachmentFileSize = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.AttachmentFileSize)).ToList(); var dsAttachmentFileSize = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.AttachmentFileSize)).ToList();
dsAttachmentFileSize = Util.DataUtil.LargestTriangleThreeBuckets(dsAttachmentFileSize, (int)maxRecords) as List<Tuple<double, double>>; dsAttachmentFileSize = Util.DataUtil.LargestTriangleThreeBuckets(dsAttachmentFileSize, (int)maxRecords) as List<Tuple<double, double>>;
var dsAttachmentFilesAvailableSpace = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.AttachmentFilesAvailableSpace)).ToList();
dsAttachmentFilesAvailableSpace = Util.DataUtil.LargestTriangleThreeBuckets(dsAttachmentFilesAvailableSpace, (int)maxRecords) as List<Tuple<double, double>>;
var dsUtilityFileCount = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFileCount)).ToList(); var dsUtilityFileCount = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFileCount)).ToList();
dsUtilityFileCount = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFileCount, (int)maxRecords) as List<Tuple<double, double>>; dsUtilityFileCount = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFileCount, (int)maxRecords) as List<Tuple<double, double>>;
var dsUtilityFileSize = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFileSize)).ToList(); var dsUtilityFileSize = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFileSize)).ToList();
dsUtilityFileSize = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFileSize, (int)maxRecords) as List<Tuple<double, double>>; dsUtilityFileSize = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFileSize, (int)maxRecords) as List<Tuple<double, double>>;
var dsUtilityFilesAvailableSpace = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFilesAvailableSpace)).ToList();
dsUtilityFilesAvailableSpace = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFilesAvailableSpace, (int)maxRecords) as List<Tuple<double, double>>;
var MetricDD = new var MetricDD = new
{ {
attachmentFileCount = dsAttachmentFileCount.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(), attachmentFileCount = dsAttachmentFileCount.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(),
attachmentFileSize = dsAttachmentFileSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(), attachmentFileSize = dsAttachmentFileSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(),
attachmentFilesAvailableSpace = dsAttachmentFilesAvailableSpace.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(),
UtilityFileCount = dsUtilityFileCount.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(), UtilityFileCount = dsUtilityFileCount.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(),
UtilityFileSize = dsUtilityFileSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray() UtilityFileSize = dsUtilityFileSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(),
UtilityFilesAvailableSpace = dsUtilityFilesAvailableSpace.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray()
}; };

View File

@@ -19,7 +19,10 @@ namespace AyaNova.Biz
private static Process _process = Process.GetCurrentProcess(); private static Process _process = Process.GetCurrentProcess();
private static TimeSpan _oldCPUTime = TimeSpan.Zero; private static TimeSpan _oldCPUTime = TimeSpan.Zero;
private static DateTime _lastSnapshot = DateTime.UtcNow; private static DateTime _lastMMSnapshot = DateTime.UtcNow;
private static DateTime _lastHHSnapshot = DateTime.UtcNow;
private static DateTime _lastDDSnapshot = DateTime.UtcNow;
// private static DateTime _lastRpsTime = DateTime.UtcNow; // private static DateTime _lastRpsTime = DateTime.UtcNow;
private static double _cpu = 0; private static double _cpu = 0;
@@ -39,67 +42,66 @@ namespace AyaNova.Biz
{ {
//Nothing is gathered less than one minute frequency if (DateUtil.IsAfterDuration(_lastMMSnapshot, tsOneHour))
if (!DateUtil.IsAfterDuration(_lastSnapshot, tsOneMinute))
return;
log.LogTrace("Starting metrics snapshot");
/////////////////////////////////////////////
//ONE MINUTE SNAPS
//
var now = DateTime.UtcNow;
_process.Refresh();
//CPU
var cpuElapsedTime = now.Subtract(_lastSnapshot).TotalMilliseconds;
var newCPUTime = _process.TotalProcessorTime;
var elapsedCPU = (newCPUTime - _oldCPUTime).TotalMilliseconds;
_cpu = elapsedCPU * 100 / Environment.ProcessorCount / cpuElapsedTime;
_oldCPUTime = newCPUTime;
//MEMORY
// The memory occupied by objects.
var Allocated = GC.GetTotalMemory(false);//bigint
// The working set includes both shared and private data. The shared data includes the pages that contain all the
// instructions that the process executes, including instructions in the process modules and the system libraries.
var WorkingSet = _process.WorkingSet64;//bigint
// The value returned by this property represents the current size of memory used by the process, in bytes, that
// 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, server stats
//need to be captured / viewed independently (digital ocean control panel for example or windows task manager)
var CPU = _cpu;// double precision
//System.Diagnostics.Debug.WriteLine($"MM Snapshot, cpu: {CPU}");
using (AyContext ct = ServiceProviderProvider.DBContext)
{ {
//write to db /////////////////////////////////////////////
MetricMM mm = new MetricMM(Allocated, WorkingSet, PrivateBytes, Gen0, Gen1, Gen2, CPU); //ONE MINUTE SNAPS
ct.MetricMM.Add(mm); //
ct.SaveChanges(); log.LogTrace("MM metrics snapshot");
//System.Diagnostics.Debug.WriteLine("MM SAVED"); var now = DateTime.UtcNow;
} _process.Refresh();
//CPU
var cpuElapsedTime = now.Subtract(_lastMMSnapshot).TotalMilliseconds;
var newCPUTime = _process.TotalProcessorTime;
var elapsedCPU = (newCPUTime - _oldCPUTime).TotalMilliseconds;
_cpu = elapsedCPU * 100 / Environment.ProcessorCount / cpuElapsedTime;
_oldCPUTime = newCPUTime;
//MEMORY
// The memory occupied by objects.
var Allocated = GC.GetTotalMemory(false);//bigint
// The working set includes both shared and private data. The shared data includes the pages that contain all the
// instructions that the process executes, including instructions in the process modules and the system libraries.
var WorkingSet = _process.WorkingSet64;//bigint
// The value returned by this property represents the current size of memory used by the process, in bytes, that
// 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, server stats
//need to be captured / viewed independently (digital ocean control panel for example or windows task manager)
var CPU = _cpu;// double precision
//System.Diagnostics.Debug.WriteLine($"MM Snapshot, cpu: {CPU}");
using (AyContext ct = ServiceProviderProvider.DBContext)
{
//write to db
MetricMM mm = new MetricMM(Allocated, WorkingSet, PrivateBytes, Gen0, Gen1, Gen2, CPU);
ct.MetricMM.Add(mm);
ct.SaveChanges();
//System.Diagnostics.Debug.WriteLine("MM SAVED");
}
_lastMMSnapshot = now;
}
///////////////////////////////////////////// /////////////////////////////////////////////
//EVERY HOUR SNAPS //EVERY HOUR SNAPS
// //
if (DateUtil.IsAfterDuration(_lastSnapshot, tsOneHour)) if (DateUtil.IsAfterDuration(_lastHHSnapshot, tsOneHour))
{ {
var now = DateTime.UtcNow;
log.LogTrace("HH metrics snapshot");
//RECORDS IN TABLE //RECORDS IN TABLE
// //Only do this once per hour // //Only do this once per hour
// log.LogTrace("Counting table records"); // log.LogTrace("Counting table records");
@@ -130,19 +132,19 @@ namespace AyaNova.Biz
// // var jobtag = new MetricTags("JobStatus", stat.ToString()); // // var jobtag = new MetricTags("JobStatus", stat.ToString());
// // metrics.Measure.Gauge.SetValue(MetricsRegistry.JobsGauge, jobtag, await JobsBiz.GetCountForJobStatusAsync(ct, stat)); // // metrics.Measure.Gauge.SetValue(MetricsRegistry.JobsGauge, jobtag, await JobsBiz.GetCountForJobStatusAsync(ct, stat));
// } // }
_lastHHSnapshot = now;
} }
///////////////////////////////////////////// /////////////////////////////////////////////
//ONCE A DAY SNAPS AND CLEANUP //ONCE A DAY SNAPS AND CLEANUP
// //
if (DateUtil.IsAfterDuration(_lastSnapshot, ts24Hours)) if (DateUtil.IsAfterDuration(_lastDDSnapshot, ts24Hours))
{ {
log.LogTrace("DD metrics snapshot");
var now = DateTime.UtcNow;
//FILES ON DISK //FILES ON DISK
var UtilFilesInfo = FileUtil.GetUtilityFolderSizeInfo(); var UtilFilesInfo = FileUtil.GetUtilityFolderSizeInfo();
var AttachmentFilesInfo = FileUtil.GetAttachmentFolderSizeInfo(); var AttachmentFilesInfo = FileUtil.GetAttachmentFolderSizeInfo();
@@ -154,21 +156,20 @@ namespace AyaNova.Biz
using (AyContext ct = ServiceProviderProvider.DBContext) using (AyContext ct = ServiceProviderProvider.DBContext)
{ {
//write to db //write to db
MetricDD dd = new MetricDD(){ MetricDD dd = new MetricDD()
AttachmentFileSize= AttachmentFilesInfo.SizeWithChildren, {
AttachmentFileCount=AttachmentFilesInfo.FileCountWithChildren, AttachmentFileSize = AttachmentFilesInfo.SizeWithChildren,
AttachmentFilesAvailableSpace=AttachmentFilesAvailableSpace, AttachmentFileCount = AttachmentFilesInfo.FileCountWithChildren,
UtilityFileSize=UtilFilesInfo.SizeWithChildren, AttachmentFilesAvailableSpace = AttachmentFilesAvailableSpace,
UtilityFileCount=UtilFilesInfo.FileCountWithChildren, UtilityFileSize = UtilFilesInfo.SizeWithChildren,
UtilityFilesAvailableSpace=UtilityFilesAvailableSpace UtilityFileCount = UtilFilesInfo.FileCountWithChildren,
UtilityFilesAvailableSpace = UtilityFilesAvailableSpace
}; };
ct.MetricDD.Add(dd); ct.MetricDD.Add(dd);
ct.SaveChanges(); ct.SaveChanges();
} }
///////////////////////////////// /////////////////////////////////
//CLEAR OLD ENTRIES //CLEAR OLD ENTRIES
// //
@@ -178,12 +179,13 @@ namespace AyaNova.Biz
{ {
ct.Database.ExecuteSqlInterpolated($"delete from ametricmm where t < {ClearDate}"); ct.Database.ExecuteSqlInterpolated($"delete from ametricmm where t < {ClearDate}");
} }
_lastDDSnapshot = now;
} }
_lastSnapshot = now; //----
} }