CodeLogic.SystemStats 4.6.72

This package has a SemVer 2.0.0 package version: 4.6.72+5b7568e.
dotnet add package CodeLogic.SystemStats --version 4.6.72
                    
NuGet\Install-Package CodeLogic.SystemStats -Version 4.6.72
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeLogic.SystemStats" Version="4.6.72" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeLogic.SystemStats" Version="4.6.72" />
                    
Directory.Packages.props
<PackageReference Include="CodeLogic.SystemStats" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CodeLogic.SystemStats --version 4.6.72
                    
#r "nuget: CodeLogic.SystemStats, 4.6.72"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CodeLogic.SystemStats@4.6.72
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CodeLogic.SystemStats&version=4.6.72
                    
Install as a Cake Addin
#tool nuget:?package=CodeLogic.SystemStats&version=4.6.72
                    
Install as a Cake Tool

CodeLogic.SystemStats

NuGet License: MIT

Cross-platform CPU, memory, uptime, and process statistics for CodeLogic 4 — one API over Windows performance counters and Linux /proc.

Samples live system metrics through platform-specific providers: Windows reads CPU info from the registry, CPU usage from PerformanceCounter, and total/available RAM via the GlobalMemoryStatusEx P/Invoke; Linux reads /proc/cpuinfo, /proc/stat, /proc/meminfo, and /proc/uptime. Every data method returns a Result<T>, results are cached for a short window, and breaching CPU/memory thresholds publishes events on the CodeLogic event bus.

Install

dotnet add package CodeLogic.SystemStats

Quick start

using CL.SystemStats;

await Libraries.LoadAsync<SystemStatsLibrary>();   // register before ConfigureAsync()
await CodeLogic.ConfigureAsync();
await CodeLogic.StartAsync();

var sys = Libraries.Get<SystemStatsLibrary>();

// Every data method returns Result<T>: check IsSuccess, then read Value.
Result<CpuStats> cpu = await sys.GetCpuStatsAsync();
if (cpu.IsSuccess)
    Console.WriteLine($"CPU: {cpu.Value!.OverallUsagePercent:F1}%");

Result<MemoryStats> mem = await sys.GetMemoryStatsAsync();
if (mem.IsSuccess)
    Console.WriteLine($"RAM: {mem.Value!.UsagePercent:F1}% ({mem.Value.UsedMiB} MiB used)");

// One combined reading: CPU + memory + uptime + top processes.
Result<SystemSnapshot> snap = await sys.GetSystemSnapshotAsync();

Features

  • CPU — static CpuInfo (model, cores, vendor, max speed, architecture) via GetCpuInfoAsync(), and live CpuStats (overall + per-core usage) via GetCpuStatsAsync() with configurable sampling.
  • Memory — static MemoryInfo (total RAM) and live MemoryStats (used / available / cached / buffers / percent), each with MiB/GiB helper properties.
  • Uptime — system uptime since last boot via GetSystemUptimeAsync().
  • Processes — enumerate all (GetAllProcessesAsync), query by PID (GetProcessStatsAsync), or rank by CPU / memory (GetTopProcessesByCpuAsync / GetTopProcessesByMemoryAsync).
  • SnapshotsGetSystemSnapshotAsync() rolls CPU, memory, uptime, and top processes into one SystemSnapshot.
  • Threshold events — publishes HighCpuUsageEvent / HighMemoryUsageEvent when usage crosses the configured limits, and SystemSnapshotTakenEvent after each snapshot.
  • Result caching — short-lived caching of common reads; clear it with sys.Stats.ClearCache().

Configuration

Auto-generated on first run as config.systemstats.json (section systemstats):

{
  "EnableCaching": true,
  "CacheDurationSeconds": 5,
  "CpuSamplingIntervalMs": 100,
  "CpuSamplesForAverage": 3,
  "EnableTemperatureMonitoring": true,
  "EnableProcessMonitoring": true,
  "MaxTopProcesses": 10,
  "HighCpuThresholdPercent": 90.0,
  "HighMemoryThresholdPercent": 90.0
}
Setting Default Description
EnableCaching true Cache common reads for CacheDurationSeconds.
CacheDurationSeconds 5 Cache lifetime in seconds (1–600).
CpuSamplingIntervalMs 100 Delay between CPU samples in ms (1–10000).
CpuSamplesForAverage 3 Number of CPU samples averaged per reading (1–20).
EnableTemperatureMonitoring true Reserved for temperature sampling support.
EnableProcessMonitoring true Enable process enumeration / ranking.
MaxTopProcesses 10 Default count for top-process queries (1–200).
HighCpuThresholdPercent 90.0 CPU usage that triggers HighCpuUsageEvent (1–100).
HighMemoryThresholdPercent 90.0 Memory usage that triggers HighMemoryUsageEvent (1–100).

Documentation

Full guide: CL.SystemStats documentation

Requirements

  • CodeLogic 4 · .NET 10
  • Windows: System.Diagnostics.PerformanceCounter 9.x · System.Management 9.x
  • Linux: read access to the /proc filesystem

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.6.72 51 6/20/2026
4.6.69-preview 41 6/20/2026
4.5.2 108 5/24/2026
4.5.2-preview.68 61 6/20/2026
4.5.1 104 5/24/2026
4.5.1-preview.56 60 5/24/2026
4.4.2-preview.53 59 5/24/2026
4.4.1 104 5/24/2026
4.0.5 98 5/15/2026
4.0.4 111 5/9/2026
4.0.3 115 5/9/2026
3.3.1 108 4/18/2026
3.3.0 114 4/18/2026
3.2.11 122 4/18/2026
3.2.10 108 4/18/2026
3.2.9 105 4/18/2026
3.2.8 108 4/18/2026
3.2.7 106 4/18/2026
3.2.6 108 4/18/2026
3.2.5 108 4/18/2026
Loading failed

# CL.SystemStats — Changelog

All notable changes to **CodeLogic.SystemStats** are documented here. Versions follow
[Semantic Versioning](https://semver.org/).

## 2026-06-20

### Fixed

- `GetTopProcessesByCpuAsync` now measures real per-process CPU usage by
 sampling each process's processor time over an interval, instead of sorting by
 a value that was always 0 (which returned an arbitrary order). Sampling uses
 the configured `CpuSamplingIntervalMs`.

### Documentation

- Full rewrite of the README and the system-stats guide to the shared house
 style: concise NuGet-friendly README (badges, tagline, install, quick start,
 features, configuration table, docs link, requirements) and a single deep docs
 page at `docs/libs/systemstats.md`.
- Documented the cross-platform provider split (Windows registry / PerformanceCounter /
 `GlobalMemoryStatusEx` / `TickCount64` vs. Linux `/proc`), with the unknown-platform
 fall back to the Linux provider.
- Covered every method as `Task<Result<T>>` and the `SystemStatsLibrary` forwarding
 surface alongside the `Stats` service (`ClearCache`, `GetPlatformInfo`, `IsInitialized`).
- Clarified that per-process `CpuUsagePercent` is `0.0` on both platforms
 (point-in-time, not sampled), that `HandleCount` is the fd count on Linux, and
 that `CachedBytes` / `BuffersBytes` are `0` on Windows.
- Documented which calls are cached vs. uncached, the published events and which
 methods trigger threshold checks, the validated `config.systemstats.json`
 fields with ranges, and the health-check states.

## [4.5.1] — 2026-06-20

### Documentation

- Rewrote the system-monitoring guide and refreshed the README to match the
 current API: `Result<T>`-returning methods, static info accessors
 (`GetCpuInfoAsync` / `GetMemoryInfoAsync`), `GetSystemUptimeAsync`,
 `GetAllProcessesAsync`, and the `CpuInfo` / `CpuStats` / `MemoryInfo` /
 `MemoryStats` / `ProcessStats` / `SystemSnapshot` record shapes (including
 MiB/GiB helper properties).
- Documented the published events (`SystemSnapshotTakenEvent`,
 `HighCpuUsageEvent`, `HighMemoryUsageEvent`) and which calls trigger threshold
 checks.
- Documented result caching behavior, the cached vs. uncached calls, and
 `ClearCache()` via the `Stats` property.
- Corrected the configuration reference to the real `config.systemstats.json`
 fields and value ranges.

## [4.5.0] — 2026-05-24

### Changed

- **Unified versioning.** All CodeLogic.Libs now share a single version line
 controlled by `version.txt` in the repo root. This is a version alignment
 release — no functional changes to this library.
## [4.0.4] — 2026-04-16

### Changed

- README + manifest refresh for the v4 baseline. No functional changes vs 4.0.3.
- `LibraryManifest.Version` now reads from assembly metadata.

## [4.0.2] — 2026-04-09

### Changed

- Annotated SystemStats configuration with `[ConfigField]` for the admin UI surface.
- Aligned with the v4 baseline across all libraries.

### Fixed

- Removed the Windows-only condition on transitive dependencies so the
 library actually loads on Linux containers.

## [4.0.0] — 2026-04-09

Major rewrite. Republished as v4.0.0 to reset the version line under the
unified v4 baseline. Cross-platform CPU / memory / disk / network sampling
backed by Windows performance counters and Linux `/proc`.

### Notes

- Earlier history is retained in the
 [git log](https://github.com/Media2A/CodeLogic.Libs/commits/main/CL.SystemStats).