AspNetCore.Live.Api.HealthChecks.Client 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AspNetCore.Live.Api.HealthChecks.Client --version 1.1.1                
NuGet\Install-Package AspNetCore.Live.Api.HealthChecks.Client -Version 1.1.1                
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="AspNetCore.Live.Api.HealthChecks.Client" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.Live.Api.HealthChecks.Client --version 1.1.1                
#r "nuget: AspNetCore.Live.Api.HealthChecks.Client, 1.1.1"                
#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 AspNetCore.Live.Api.HealthChecks.Client as a Cake Addin
#addin nuget:?package=AspNetCore.Live.Api.HealthChecks.Client&version=1.1.1

// Install AspNetCore.Live.Api.HealthChecks.Client as a Cake Tool
#tool nuget:?package=AspNetCore.Live.Api.HealthChecks.Client&version=1.1.1                

LiveHealthChecks

Real-Time Api Health Check Monitoring

Packages Version & Downloads
AspNetCore.Live.Api.HealthChecks.Server NuGet Version and Downloads count
AspNetCore.Live.Api.HealthChecks.Client NuGet Version and Downloads count

Background

An Asp Net Core Web Api has a Health Checks system built into it.

This project taps into that system & makes the generated Health Report,

available to Monitoring applications, in real-time.

The Client package, installed in the Api, runs the Health Check periodically,

and uploads the generated Health Report to the Server SignalR Hub.

The Hub sends a web socket push notification to the connected clients,

notifying them of the Health Report in real-time.

Server

You can use a Console app as a Health Checks Server.

Just create one with Web Sdk (project file):

<Project Sdk="Microsoft.NET.Sdk.Web">

Then, plug in the Server package.

var builder = WebApplication.CreateBuilder();

builder.Services.AddSignalR();
builder.Services.AddLiveHealthChecksServer(settings => settings.SecretKey = "43bf0968-17e0-4d22-816a-6eaadd766692");

var app = builder.Build();

app.UseRouting();
app.UseEndpoints(endpoints =>
{
    endpoints.MapHub<LiveHealthChecksHub>("/livehealthcheckshub");
});

app.Run();

Asp Net Core Api

In your Api add the Client Nuget package.

then

builder.Services.AddHealthChecks() //Required - add all your health checks
                .AddLiveHealthChecksClient(settings =>
                {
                    settings.HealthCheckIntervalInMinutes = 60;
                    settings.ReceiveMethod = "SampleApiHealth";
                    settings.HealthCheckServerHubUrl = "https://localhost:5001/livehealthcheckshub";
                    settings.SecretKey = "43bf0968-17e0-4d22-816a-6eaadd766692";
                    settings.PublishOnlyWhenNotHealthy = false;
                    //Optional - transform your health report to as you want it published.
                    settings.TransformHealthReport = healthReport => new
                    {
                        status = healthReport.Status.ToString(),
                        results = healthReport.Entries.Select(e => new
                        {
                            key = e.Key,
                            value = e.Value.Status.ToString()
                        })
                    };
                });

The ReceiveMethod is the SignalR method that Monitoring app needs to listen to.

The SecretKey must be the same between Server & Api.

Set PublishOnlyWhenNotHealthy to true if you want to publish anomalies,

ie those Health Reports with not Healthy status.

The Server sends the Health Report as a real-time push notification.

Note:- You can host a Server & Client in the same Api too.

Monitoring app

In your Monitoring app, create a SignalR connection to the Server Hub.

Then, start listening to the set ReceiveMethod ie "SampleApiHealth".

var connection = new HubConnectionBuilder()
                        .WithUrl("https://localhost:5001/livehealthcheckshub")
                        .WithAutomaticReconnect()
                        .Build();

connection.On("SampleApiHealth", new Type[] {typeof(object), typeof(object)},
    (arg1, arg2) =>
    {
        Console.WriteLine(arg1[0]);
        return Task.CompletedTask;
    }, new object());

await connection.StartAsync();

Live - Trigger your own Health Checks

Besides, the Client package running the Health Check on the Api it self, periodically,

you can run your own Health Check and publish the Health Report to the Server.

You can trigger your own Health Check, at any point, in your API,

by injecting the built-in Health Check system's' HealthCheckService,

and calling the CheckHealthAsync method.

and then, publish the Health Report to the Server your self,

by injecting IMyHealthCheckPublisher and calling the Publish method.

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 was computed.  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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 81 10/8/2024
2.1.0 83 8/5/2024
2.0.0 129 3/17/2024
1.6.0 166 8/21/2023
1.5.0 173 7/24/2023
1.4.1 183 7/17/2023
1.4.0 175 7/10/2023
1.3.0 171 7/3/2023
1.2.0 161 6/26/2023
1.1.1 145 6/19/2023
1.1.0 168 6/15/2023
1.0.0 147 6/13/2023

Added feature to run health check on startup of api. Added extension to add client, to IHealthChecksBuilder.