Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization

Resource utilization health check.
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](https://learn.microsoft.com/aspnet/core/host-and-deploy/health-checks) documentation for general usage guidance.

## Install the package

Expand All @@ -18,6 +18,50 @@ Or directly in the C# project file:
</ItemGroup>
```

## Usage Example

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

```csharp
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:

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddHealthChecks()
.AddResourceUtilizationHealthCheck(o =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, is 'o' just the convention in extensions land for the param going to these builder delegates? or it is meant to stand for something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is shorthand for options.

{
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 report as degraded or unhealthy unless configured. The `SamplingWindow` defaults to 5 seconds.

## Feedback & Contributing

Expand Down