Oakrey.Applications.Performance
7.0.1
dotnet add package Oakrey.Applications.Performance --version 7.0.1
NuGet\Install-Package Oakrey.Applications.Performance -Version 7.0.1
<PackageReference Include="Oakrey.Applications.Performance" Version="7.0.1" />
<PackageVersion Include="Oakrey.Applications.Performance" Version="7.0.1" />
<PackageReference Include="Oakrey.Applications.Performance" />
paket add Oakrey.Applications.Performance --version 7.0.1
#r "nuget: Oakrey.Applications.Performance, 7.0.1"
#:package Oakrey.Applications.Performance@7.0.1
#addin nuget:?package=Oakrey.Applications.Performance&version=7.0.1
#tool nuget:?package=Oakrey.Applications.Performance&version=7.0.1
Oakrey.Applications.Performance
A .NET 10 Windows library for observing application CPU and RAM usage through Rx streams.
NuGet package ID: Oakrey.Applications.Performance
Main features
CpuUsageexposes the latest CPU percentage asIObservable<int>.RamUsageexposes the latest RAM usage in MB asIObservable<int>.Usageexposes the original combinedPerformanceLogstream.- CPU and RAM streams immediately publish an initial value of zero to new subscribers.
- The polling period is configurable and must be greater than zero.
PerformanceMonitoringLoggingServicelogs samples using placeholder-based Oakrey logging.- Monitoring, subscriptions, subjects, and the underlying Windows monitor have idempotent cleanup.
- Source errors are logged and forwarded to the derived CPU and RAM streams.
Architecture
classDiagram
class IPerformanceMonitoringService {
+IObservable~int~ CpuUsage
+IObservable~int~ RamUsage
+IObservable~PerformanceLog~ Usage
}
class PerformanceMonitoringService {
+PerformanceMonitoringService()
+PerformanceMonitoringService(msPeriod)
+Dispose()
}
class PerformanceMonitoringLoggingService {
+Preload(cancellationToken) Task
+Subscribe(observer) IDisposable
+Dispose()
}
IPerformanceMonitoringService <|.. PerformanceMonitoringService
PerformanceMonitoringLoggingService --> IPerformanceMonitoringService
No public interface signatures are changed by the current implementation.
Requirements and direct dependencies
- .NET 10 for Windows
Oakrey.Debug.Windows3.0.1Oakrey.Log.Abstractions3.0.0System.Reactive6.1.0- Project reference to
Oakrey.Applications.AbstractionsforIPreLoadableandPreLoadingException
All package references are direct, current, and checked for known vulnerabilities.
Installation
dotnet add package Oakrey.Applications.Performance
Package Manager Console:
Install-Package Oakrey.Applications.Performance
Usage
using Oakrey.Applications.Performance;
using PerformanceMonitoringService monitoring =
new(msPeriod: 1000);
using IDisposable cpuSubscription = monitoring.CpuUsage.Subscribe(
cpu => Console.WriteLine($"CPU: {cpu}%"));
using IDisposable ramSubscription = monitoring.RamUsage.Subscribe(
ram => Console.WriteLine($"RAM: {ram} MB"));
The native monitor can require an initialization period before its first sampled value. The initial zero from each BehaviorSubject is available immediately.
Automatic logging
using PerformanceMonitoringService monitoring = new();
using PerformanceMonitoringLoggingService logging = new(monitoring);
await logging.Preload(cancellationToken);
The logging service subscribes during construction and records each combined sample at information level:
CPU: {0}%, RAM: {1} MB
The placeholders are formatted by the Oakrey logger with CPU and RAM supplied as separate arguments.
Dependency injection
services.AddSingleton<IPerformanceMonitoringService, PerformanceMonitoringService>();
services.AddSingleton<PerformanceMonitoringLoggingService>();
Register the concrete monitoring service for disposal when callers also need to resolve it directly. The current IPerformanceMonitoringService contract does not inherit IDisposable.
Lifecycle and safety notes
- A non-positive polling period throws
ArgumentOutOfRangeException. - Observable wrappers are cached instead of allocated on every property access.
- Performance callbacks and disposal are synchronized.
- Subscriber failures are logged without stopping cleanup of the other streams.
- Source errors are propagated through
CpuUsageandRamUsage. - Disposal is safe to call more than once.
Preloadrespects an already-cancelled token and rejects use after disposal.- The preload exception replay buffer is limited to one item and is completed during disposal.
- Information-level sample logging can produce significant log volume at short polling periods. Choose the period according to operational needs.
- CPU and RAM measurements are operational metadata. Consider access controls and retention policy when exporting logs.
License
MIT - Copyright (c) Oakrey 2016-present
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- Oakrey.Applications.Abstractions (>= 7.0.0)
- Oakrey.Debug.Windows (>= 3.0.1)
- Oakrey.Log.Abstractions (>= 3.0.0)
- System.Reactive (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.