Pdsr.HealthChecks 2.3.0

dotnet add package Pdsr.HealthChecks --version 2.3.0                
NuGet\Install-Package Pdsr.HealthChecks -Version 2.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pdsr.HealthChecks" Version="2.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pdsr.HealthChecks --version 2.3.0                
#r "nuget: Pdsr.HealthChecks, 2.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pdsr.HealthChecks as a Cake Addin
#addin nuget:?package=Pdsr.HealthChecks&version=2.3.0

// Install Pdsr.HealthChecks as a Cake Tool
#tool nuget:?package=Pdsr.HealthChecks&version=2.3.0                

Pdsr HealthChecks Libraries

Contains HealthChecks for OpenId-Connect, RedisCacheManager, Postgres, and RabbitMQ.

Getting Started

Health checks need to register in the DI container.

Redis Healthcheck

In the minimal API, use builder.Services to add the extension method, AddRedisCacheManager to IHealthChecksBuilder.

var degradedThreshold = 50;     // in milliseconds, response time higher than 50 will be considered degraded
var unhealthyThreshold = 100;   // in milliseconds, response time higher than 100 will be considered unhealthy
builder.Services.AddHealthChecks()
    .AddRedisCacheManager(degradedThreshold,unhealthyThreshold);

Memory HealthCheck

You can define a memory usage limit for the MemoryHealthCheck

In the minimal API, use builder.Services to add the extension method, AddMemoryHealthCheck to IHealthChecksBuilder

builder.Services.AddHealthChecks()
    .AddMemoryHealthCheck(
        degradedThreshold: 50 * 1024L * 1024L,      // shows degraded at this 50 MB
        unhealthyThreshold: 100 * 2048L * 2048L,    // threshold to show failureStatus (unhealthy), 100MB
        failureStatus: HealthStatus.Unhealthy,      // default failure status is HealthStatus.Unhealthy
        tags: new string[] { "memory", "ram" });    // optional tags

Health Publisher

The interface ISystemHealth and the abstract class SystemHealthBase are available to be used as publisher.

you need to inherit from SystemHealthBase:

public class MyHealthStatus : SystemHealthBase
{
    // some custom properties
}

Register in DI container

builder.Services.RegisterReadinessPublisher<MyHealthStatus>();

The instance of MyHealthStatus is available through injection.

public class SomeService : ISomeService
{
    private readonly MySystemHealth _mySystemHealth;
    public SomeService(MySystemHealth mySystemHealth)
    {
        _mySystemHealth = _mySystemHealth;
    }

    public void SomeMethod()
    {
        var health = _mySystemHealth.HealthReport;
        // do whatever you like with that health status.
    }
}

Samples

Refer to the samples folder.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Pdsr.HealthChecks:

Package Downloads
Pdsr.HealthChecks.Npgsql

Npgsql Postgres Healthchecks

Pdsr.HealthChecks.Redis

Redis Cache Manager HealthCheck system.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 773 2/20/2024
2.2.3 221 9/17/2023
2.2.2 200 8/30/2023
2.2.1 593 2/20/2023
2.2.0 2,754 11/11/2022
2.1.1 725 8/26/2022
2.1.0 823 5/11/2022
2.0.3 775 4/18/2022