Skip to main content
Published
Feb 13, 2024
2y ago
Total Downloads
1.9M
1,878,422

Install

dotnet add package Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization --version 9.0.0-preview.1.24108.1
ProductVersions
.NET
net8.0net9.0
Other
.NETFramework4.6.2

README

Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization

This provides configurable health check reporting based on the current system resource utilization. See Microsoft.Extensions.Diagnostics.ResourceMonitoring for details on how resources are measured. See the health checks documentation for general usage guidance.

Install the package

From the command-line:

dotnet add package Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization

Or directly in the C# project file:

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization" Version="[CURRENTVERSION]" />
</ItemGroup>

Usage Example

The health check services can be registered and configured using any of the following API:

public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, params string[] tags)
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, IEnumerable<string> tags)
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, IConfigurationSection section)
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, IConfigurationSection section, params string[] tags)
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, IConfigurationSection section, IEnumerable<string> tags)
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, Action<ResourceUtilizationHealthCheckOptions> configure)
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, Action<ResourceUtilizationHealthCheckOptions> configure, params string[] tags)
public static IHealthChecksBuilder AddResourceUtilizationHealthCheck(this IHealthChecksBuilder builder, Action<ResourceUtilizationHealthCheckOptions> configure, IEnumerable<string> tags)

For example:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddHealthChecks()
    .AddResourceUtilizationHealthCheck(o =>
    {
        o.CpuThresholds = new ResourceUsageThresholds
        {
            DegradedUtilizationPercentage = 80,
            UnhealthyUtilizationPercentage = 90,
        };
        o.MemoryThresholds = new ResourceUsageThresholds
        {
            DegradedUtilizationPercentage = 80,
            UnhealthyUtilizationPercentage = 90,
        };
        o.SamplingWindow = TimeSpan.FromSeconds(5);
    });

var app = builder.Build();

app.MapHealthChecks("/healthz");

app.Run();

CpuThresholds and MemoryThresholds's percentages default to null and will not be reported as degraded or unhealthy unless configured. The SamplingWindow defaults to 5 seconds.

Feedback & Contributing

We welcome feedback and contributions in our GitHub repo.

Changes from Previous Version

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 3 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.