Some checks are pending
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
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:2025-latest) (push) Blocked by required conditions
CI / Build og unit tests (push) Waiting to run
Collectors (SQL Server 2000+, version-specific SQL, least privilege): server, configuration, trace flags, databases (settings, backups in UTC, CHECKDB, VLFs, Query Store, files, tempdb), suspect pages, plan cache, wait stats and file I/O as deltas with restart/clear detection, performance counters, CPU from the scheduler monitor ring buffer, blocking (sleeping head blockers with open transactions), and deadlocks from system_health continuing from the last file offset. Rules: configuration (memory, MAXDOP per Microsoft NUMA guidance, cost threshold, ad hoc bloat, risky options, pending changes), databases (state, settings, backups, log backups, CHECKDB, suspect pages, VLFs, autogrowth, max size, Query Store, tempdb), waits (THREADPOOL, signal waits, locks, I/O, WRITELOG, parallelism, PAGELATCH), I/O latency, CPU, memory grants, blocking and deadlocks. Missing data makes a rule not measurable with the collector's reason. Integration tests run every collector as the least-privilege login and reproduce real blocking and a real deadlock; green on 2017 and 2022. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
namespace SQLInsight.Core.Data;
|
|
|
|
/// <summary>
|
|
/// Selected SQL Server performance counters (<c>sys.dm_os_performance_counters</c> / <c>sysperfinfo</c>).
|
|
/// Point-in-time counters are used as-is; per-second counters are cumulative and need a delta.
|
|
/// </summary>
|
|
public sealed record PerformanceCounterSnapshot
|
|
{
|
|
public required DateTimeOffset CapturedAt { get; init; }
|
|
public required DateTime SqlServerStartTime { get; init; }
|
|
public long? MemoryGrantsPending { get; init; }
|
|
public long? MemoryGrantsOutstanding { get; init; }
|
|
public long? PageLifeExpectancySeconds { get; init; }
|
|
public long? UserConnections { get; init; }
|
|
public long? ProcessesBlocked { get; init; }
|
|
|
|
/// <summary>Cumulative since start.</summary>
|
|
public long? BatchRequests { get; init; }
|
|
|
|
/// <summary>Cumulative since start.</summary>
|
|
public long? SqlCompilations { get; init; }
|
|
|
|
/// <summary>Cumulative since start.</summary>
|
|
public long? SqlRecompilations { get; init; }
|
|
}
|
|
|
|
public sealed record PerformanceCounterRates
|
|
{
|
|
public required DateTimeOffset From { get; init; }
|
|
public required DateTimeOffset To { get; init; }
|
|
public double? BatchRequestsPerSecond { get; init; }
|
|
public double? CompilationsPerSecond { get; init; }
|
|
public double? RecompilationsPerSecond { get; init; }
|
|
|
|
public static PerformanceCounterRates? Compute(PerformanceCounterSnapshot? previous, PerformanceCounterSnapshot current)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(current);
|
|
if (previous is null || previous.SqlServerStartTime != current.SqlServerStartTime || current.CapturedAt <= previous.CapturedAt)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var seconds = (current.CapturedAt - previous.CapturedAt).TotalSeconds;
|
|
return new PerformanceCounterRates
|
|
{
|
|
From = previous.CapturedAt,
|
|
To = current.CapturedAt,
|
|
BatchRequestsPerSecond = Rate(previous.BatchRequests, current.BatchRequests, seconds),
|
|
CompilationsPerSecond = Rate(previous.SqlCompilations, current.SqlCompilations, seconds),
|
|
RecompilationsPerSecond = Rate(previous.SqlRecompilations, current.SqlRecompilations, seconds),
|
|
};
|
|
}
|
|
|
|
private static double? Rate(long? before, long? after, double seconds) =>
|
|
before is { } b && after is { } a && a >= b ? (a - b) / seconds : null;
|
|
}
|