Philiprehberger.HealthCheckKit
0.3.0
dotnet add package Philiprehberger.HealthCheckKit --version 0.3.0
NuGet\Install-Package Philiprehberger.HealthCheckKit -Version 0.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="Philiprehberger.HealthCheckKit" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.HealthCheckKit" Version="0.3.0" />
<PackageReference Include="Philiprehberger.HealthCheckKit" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Philiprehberger.HealthCheckKit --version 0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Philiprehberger.HealthCheckKit, 0.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.
#:package Philiprehberger.HealthCheckKit@0.3.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Philiprehberger.HealthCheckKit&version=0.3.0
#tool nuget:?package=Philiprehberger.HealthCheckKit&version=0.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Philiprehberger.HealthCheckKit
Composable health checks for ASP.NET Core with built-in URL, TCP, DNS, certificate, disk, and memory checks.
Installation
dotnet add package Philiprehberger.HealthCheckKit
Usage
using Philiprehberger.HealthCheckKit;
builder.Services.AddHealthCheckKit(checks => checks
.AddUrlCheck("https://api.example.com/health")
.AddTcpCheck("db-server", 5432)
.AddDnsCheck("api.example.com")
.AddCertificateCheck("api.example.com")
.AddDiskSpaceCheck(minimumFreeBytes: 500_000_000)
.AddMemoryCheck(maximumBytes: 1_073_741_824));
app.MapHealthChecks("/health");
TCP Port Connectivity
using Philiprehberger.HealthCheckKit;
builder.Services.AddHealthCheckKit(checks => checks
.AddTcpCheck("db-server", 5432)
.AddTcpCheck("redis", 6379, timeout: TimeSpan.FromSeconds(2)));
DNS Resolution
using Philiprehberger.HealthCheckKit;
builder.Services.AddHealthCheckKit(checks => checks
.AddDnsCheck("api.example.com")
.AddDnsCheck("storage.example.com"));
SSL Certificate Expiration
using Philiprehberger.HealthCheckKit;
builder.Services.AddHealthCheckKit(checks => checks
.AddCertificateCheck("api.example.com")
.AddCertificateCheck("payments.example.com", warningDays: 14));
Composite Health Report
using Philiprehberger.HealthCheckKit;
var runner = new HealthCheckKitBuilder()
.AddUrlCheck("https://api.example.com/health")
.AddTcpCheck("db-server", 5432)
.AddDnsCheck("api.example.com")
.BuildRunner();
var report = await runner.RunAllAsync();
Console.WriteLine($"Status: {report.Status}, Total: {report.TotalElapsed.TotalMilliseconds}ms");
foreach (var entry in report.Entries)
{
Console.WriteLine($" {entry.Name}: {entry.Result.Status} ({entry.Duration.TotalMilliseconds}ms)");
}
Built-in Checks
using Philiprehberger.HealthCheckKit;
// URL check — Healthy on 2xx, Degraded on timeout, Unhealthy otherwise
builder.Services.AddHealthCheckKit(checks => checks
.AddUrlCheck("https://downstream-service.example.com/ping"));
// Disk space check — Unhealthy when free space drops below threshold
builder.Services.AddHealthCheckKit(checks => checks
.AddDiskSpaceCheck(minimumFreeBytes: 500_000_000));
// Memory check — Unhealthy when managed memory exceeds limit
builder.Services.AddHealthCheckKit(checks => checks
.AddMemoryCheck(maximumBytes: 1_073_741_824));
Ping and Process Memory
using Philiprehberger.HealthCheckKit;
builder.Services.AddHealthCheckKit(checks => checks
.AddPingCheck("api.example.com")
.AddProcessMemoryCheck(maximumWorkingSetBytes: 2_147_483_648));
Tagging Checks
Each AddXxxCheck accepts a params string[] tags argument that is surfaced on the report entry:
using Philiprehberger.HealthCheckKit;
var runner = new HealthCheckKitBuilder()
.AddTcpCheck("db", 5432, tags: new[] { "infra", "critical" })
.AddUrlCheck("https://api.example.com/health", tags: new[] { "api" })
.BuildRunner();
runner.PerCheckTimeout = TimeSpan.FromSeconds(10);
var report = await runner.RunAllAsync();
foreach (var entry in report.Entries)
{
Console.WriteLine($"{entry.Name} [{string.Join(',', entry.Tags)}]: {entry.Result.Status}");
}
Custom Checks
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Philiprehberger.HealthCheckKit;
builder.Services.AddHealthCheckKit(checks => checks
.AddCustomCheck("database", async cancellationToken =>
{
var isHealthy = await CheckDatabaseConnectionAsync(cancellationToken);
return isHealthy
? HealthCheckResult.Healthy("Database is reachable.")
: HealthCheckResult.Unhealthy("Database is unreachable.");
}));
API
HealthCheckKitBuilder
| Method | Description |
|---|---|
AddUrlCheck(string url, TimeSpan? timeout = null, params string[] tags) |
Adds an HTTP GET check for the given URL |
AddTcpCheck(string host, int port, TimeSpan? timeout = null, params string[] tags) |
Adds a TCP port connectivity check |
AddDnsCheck(string hostname, params string[] tags) |
Adds a DNS resolution check |
AddCertificateCheck(string host, int warningDays = 30, params string[] tags) |
Adds an SSL certificate expiration check |
AddDiskSpaceCheck(long minimumFreeBytes, string? drivePath = null, params string[] tags) |
Adds a disk free space check |
AddMemoryCheck(long maximumBytes, params string[] tags) |
Adds a managed memory usage check |
AddProcessMemoryCheck(long maximumWorkingSetBytes, params string[] tags) |
Adds a process working-set memory check |
AddPingCheck(string host, TimeSpan? timeout = null, params string[] tags) |
Adds an ICMP ping reachability check |
AddCustomCheck(string name, Func<CancellationToken, Task<HealthCheckResult>> check, params string[] tags) |
Adds a custom delegate-based check |
BuildRunner() |
Creates a HealthCheckRunner for standalone execution |
HealthCheckRunner
| Method / Property | Description |
|---|---|
RunAllAsync(CancellationToken cancellationToken = default) |
Runs all checks and returns a composite HealthReport |
PerCheckTimeout |
Per-check timeout (default 30s); a hung check is reported as Unhealthy |
HealthReport
| Property | Type | Description |
|---|---|---|
Status |
HealthReportStatus |
Overall status: Healthy, Degraded, or Unhealthy |
Entries |
IReadOnlyList<HealthCheckEntry> |
Individual check results |
TotalElapsed |
TimeSpan |
Total time to run all checks |
HealthCheckEntry
| Property | Type | Description |
|---|---|---|
Name |
string |
Name of the health check |
Result |
HealthCheckResult |
The check result with status and description |
Duration |
TimeSpan |
How long the check took to execute |
Tags |
IReadOnlyList<string> |
Tags associated with the check |
ServiceCollectionExtensions
| Method | Description |
|---|---|
AddHealthCheckKit(this IServiceCollection services, Action<HealthCheckKitBuilder> configure) |
Registers all configured health checks with the DI container |
TcpHealthCheck
| Member | Description |
|---|---|
TcpHealthCheck(string host, int port, TimeSpan? timeout = null) |
Creates a TCP connectivity check with optional timeout (default 5s) |
CheckHealthAsync(context, cancellationToken) |
Returns Healthy if connection succeeds, Unhealthy otherwise |
DnsHealthCheck
| Member | Description |
|---|---|
DnsHealthCheck(string hostname) |
Creates a DNS resolution check for the given hostname |
CheckHealthAsync(context, cancellationToken) |
Returns Healthy if resolution returns addresses, Unhealthy otherwise |
CertificateHealthCheck
| Member | Description |
|---|---|
CertificateHealthCheck(string host, int warningDays = 30) |
Creates an SSL certificate expiration check |
CheckHealthAsync(context, cancellationToken) |
Returns Healthy, Degraded (expiring soon), or Unhealthy (expired/failed) |
UrlHealthCheck
| Member | Description |
|---|---|
UrlHealthCheck(string url, TimeSpan? timeout = null) |
Creates a URL health check with optional timeout (default 5s) |
CheckHealthAsync(context, cancellationToken) |
Returns Healthy (2xx), Degraded (timeout), or Unhealthy |
DiskSpaceHealthCheck
| Member | Description |
|---|---|
DiskSpaceHealthCheck(long minimumFreeBytes, string drivePath = "/") |
Creates a disk space check for the given drive |
CheckHealthAsync(context, cancellationToken) |
Returns Healthy if free space meets minimum, Unhealthy otherwise |
MemoryHealthCheck
| Member | Description |
|---|---|
MemoryHealthCheck(long maximumBytes) |
Creates a memory check with the given byte limit |
CheckHealthAsync(context, cancellationToken) |
Returns Healthy if within limit, Unhealthy otherwise |
Development
dotnet build src/Philiprehberger.HealthCheckKit.csproj --configuration Release
Support
If you find this project useful:
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.