namespace SQLInsight.Core.Data;
///
/// CPU use per minute from the scheduler monitor ring buffer (sys.dm_os_ring_buffers, 2005+).
/// Distinguishes SQL Server's own CPU from other processes on the host.
///
public sealed record CpuUtilization
{
public required DateTimeOffset CapturedAt { get; init; }
///
/// 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.
///
public string? HostPlatform { get; init; }
public bool OtherProcessesMeasurable => !string.Equals(HostPlatform, "Linux", StringComparison.OrdinalIgnoreCase);
/// One sample per minute, oldest first.
public required IReadOnlyList Samples { get; init; }
}
public sealed record CpuSample(DateTimeOffset Time, int SqlServerPercent, int IdlePercent)
{
public int OtherProcessesPercent => Math.Max(0, 100 - SqlServerPercent - IdlePercent);
}