-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix build loading from GWCA Introduce persistence toggle for logging to reduce disk usage Improve performance of memory usage and processor usage counters Add disk usage counters Closes #462 Closes #461
- Loading branch information
1 parent
97d2d09
commit 32efe42
Showing
11 changed files
with
173 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Daybreak.Services.Metrics; | ||
using System.Diagnostics.Metrics; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using System.Windows.Extensions.Services; | ||
using System.Core.Extensions; | ||
using System.Extensions; | ||
using System.Threading; | ||
|
||
namespace Daybreak.Services.Monitoring; | ||
|
||
public sealed class DiskUsageMonitor : IApplicationLifetimeService | ||
{ | ||
private const string WriteDiskUsage = "Write Disk Usage"; | ||
private const string WriteDiskUsageUnit = "MBs/s"; | ||
private const string WriteDiskUsageDescription = "MBs/s written by Daybreak"; | ||
private const string ReadDiskUsage = "Read Disk Usage"; | ||
private const string ReadDiskUsageUnit = "MBs/s"; | ||
private const string ReadDiskUsageDescription = "MBs/s read by Daybreak"; | ||
|
||
private readonly Histogram<double> writeDiskUsageHistogram; | ||
private readonly Histogram<double> readDiskUsageHistogram; | ||
private readonly CancellationTokenSource cancellationTokenSource = new(); | ||
|
||
private PerformanceCounter? readPerformanceCounter; | ||
private PerformanceCounter? writePerformanceCounter; | ||
|
||
public DiskUsageMonitor( | ||
IMetricsService metricsService) | ||
{ | ||
this.writeDiskUsageHistogram = metricsService.ThrowIfNull().CreateHistogram<double>(WriteDiskUsage, WriteDiskUsageUnit, WriteDiskUsageDescription, Models.Metrics.AggregationTypes.NoAggregate); | ||
this.readDiskUsageHistogram = metricsService.ThrowIfNull().CreateHistogram<double>(ReadDiskUsage, ReadDiskUsageUnit, ReadDiskUsageDescription, Models.Metrics.AggregationTypes.NoAggregate); | ||
} | ||
|
||
public void OnClosing() | ||
{ | ||
this.cancellationTokenSource.Cancel(); | ||
} | ||
|
||
public void OnStartup() | ||
{ | ||
_ = Task.Run(this.StartupAndPeriodicallyReadDiskUsage, this.cancellationTokenSource.Token); | ||
} | ||
|
||
private async Task StartupAndPeriodicallyReadDiskUsage() | ||
{ | ||
var processName = Process.GetCurrentProcess().ProcessName; | ||
this.readPerformanceCounter = new PerformanceCounter("Process", "IO Read Bytes/sec", processName); | ||
this.writePerformanceCounter = new PerformanceCounter("Process", "IO Write Bytes/sec", processName); | ||
while (!this.cancellationTokenSource.Token.IsCancellationRequested) | ||
{ | ||
try | ||
{ | ||
this.PeriodicallyCheckMemoryUsagePerfCounterBased(); | ||
await Task.Delay(1000, this.cancellationTokenSource.Token); | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
} | ||
|
||
private void PeriodicallyCheckMemoryUsagePerfCounterBased() | ||
{ | ||
this.readDiskUsageHistogram.Record(this.readPerformanceCounter?.NextValue() / 1024 / 1024 ?? 0); | ||
this.writeDiskUsageHistogram.Record(this.writePerformanceCounter?.NextValue() / 1024 / 1024 ?? 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters