Skip to content

SqlSystemMetricsReporter

github-actions[bot] edited this page Dec 6, 2026 · 3 revisions

SqlSystemMetricsReporter

SqlSystemMetricsReporter is the SQL Server implementation of BlueprintSystemMetricsReporter in the Blueprint.SystemMetricsReporter.Sql namespace. Create the reporter with the unqualified name of a table in dbo and a positive TimeSpan for retention. Initialize() creates the table when it is missing.

Connection and permissions

When a SqlDatabase is active, the reporter uses its connection settings at initialization. To use the reporter independently, provide ConnectionString in the object initializer. Specify the SQL Server and an existing database in that connection string. Initialization needs permission to create the table when it is missing. Writing needs INSERT on the table and reading needs SELECT. Deleting needs DELETE on the table and SELECT for the SampledAtUtc filter. SQL Server DELETE permissions

Use the reporter

using System;
using Blueprint.SystemMetricsReporter.Sql;

using (SqlSystemMetricsReporter reporter = new SqlSystemMetricsReporter("SystemMetrics", TimeSpan.FromMinutes(30)))
{
    reporter.Initialize();
    reporter.WriteReport();
}

The example assumes an active SqlDatabase. Call WriteReport() on your application's schedule. Use the shared API to read samples, list machine names, or delete expired reports.

SQL Server table

Each row contains the originating machine name, CPU usage, system RAM, application RAM, and the SampledAtUtc timestamp. New tables store SampledAtUtc as datetime2(0) and create a nonclustered index on that column for date-range reads and retention cleanup.

Call DeleteExpiredReports() whenever your application needs to clean up old reports. The cutoff applies to the whole table, including rows recorded by other machines.

User manual

Clone this wiki locally