sqlinsight-pro/src/SQLInsight.Core/Data/CpuUtilization.cs
Claude 5bb1c37fef
Some checks are pending
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
CI / Build og unit tests (push) Waiting to run
Fase 1: on-prem web UI (IIS or Windows service), light design system
- ASP.NET Core Blazor static SSR: overview with KPI tiles, instance page
  (findings, CPU/batch/PLE trends, top waits, file latency, blocking,
  deadlocks with .xdl download, not-measurable rules, resolved), finding
  detail with explanation, evidence, fix script and references
- Light-first design (sidebar, cards, self-hosted Inter, teal accent),
  optional dark theme via toggle; strict CSP, no inline styles
- Windows authentication (Negotiate/IIS) with optional group restriction;
  refuses to run without authentication outside Development
- Hosting: IIS (in-process ASP.NET Core Module), Windows service with
  Kestrel, or systemd; web reads the repository with db_datareader only
- docs/installation.md for repository, permissions, agent and web
- Fix: CPU used by other processes is not derived on Linux (SystemIdle is
  unreliable there); deadlocks are not re-reported or stored twice after
  an agent restart; Dapper sends datetime2 so time comparisons are exact

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
2026-09-29 06:58:51 +00:00

26 lines
1 KiB
C#

namespace SQLInsight.Core.Data;
/// <summary>
/// CPU use per minute from the scheduler monitor ring buffer (<c>sys.dm_os_ring_buffers</c>, 2005+).
/// Distinguishes SQL Server's own CPU from other processes on the host.
/// </summary>
public sealed record CpuUtilization
{
public required DateTimeOffset CapturedAt { get; init; }
/// <summary>
/// Windows or Linux (2017+). On Linux the ring buffer's SystemIdle is not reliable (it reads near 0 in
/// containers), so CPU used by other processes cannot be derived.
/// </summary>
public string? HostPlatform { get; init; }
public bool OtherProcessesMeasurable => !string.Equals(HostPlatform, "Linux", StringComparison.OrdinalIgnoreCase);
/// <summary>One sample per minute, oldest first.</summary>
public required IReadOnlyList<CpuSample> Samples { get; init; }
}
public sealed record CpuSample(DateTimeOffset Time, int SqlServerPercent, int IdlePercent)
{
public int OtherProcessesPercent => Math.Max(0, 100 - SqlServerPercent - IdlePercent);
}