![]() |
VOOZH | about |
See https://petabridge.com/blog/you-dont-need-akka-healthchecks-anymore/ - all of the functionality from Akka.HealthChecks is now built-in to Akka.Hosting, with fewer bugs and configuration overhead.
dotnet add package Akka.HealthCheck.Hosting.Web --version 1.5.37
NuGet\Install-Package Akka.HealthCheck.Hosting.Web -Version 1.5.37
<PackageReference Include="Akka.HealthCheck.Hosting.Web" Version="1.5.37" />
<PackageVersion Include="Akka.HealthCheck.Hosting.Web" Version="1.5.37" />Directory.Packages.props
<PackageReference Include="Akka.HealthCheck.Hosting.Web" />Project file
paket add Akka.HealthCheck.Hosting.Web --version 1.5.37
#r "nuget: Akka.HealthCheck.Hosting.Web, 1.5.37"
#:package Akka.HealthCheck.Hosting.Web@1.5.37
#addin nuget:?package=Akka.HealthCheck.Hosting.Web&version=1.5.37Install as a Cake Addin
#tool nuget:?package=Akka.HealthCheck.Hosting.Web&version=1.5.37Install as a Cake Tool
This package integrates Akka.HealthCheck, Akka.Hosting, and Microsoft.AspNetCore.Diagnostics.HealthChecks, allowing users to access Akka.HealthCheck via HTTP REST API.
The package provides 5 IHealthCheck probes that can be registered with the health check middleware, each uniquely tagged so they can be individually filtered during mapping:
AkkaReadinessProbe - The default readiness probe. The probe reports the time the ActorSystem was started.
Tags: [ "akka", "ready", "node" ]
AkkaLivenessProbe - The default liveness probe. The probe reports the time the ActorSystem was started.
Tags: [ "akka", "live", "node" ]
AkkaClusterReadinessProbe - Readiness probe for clustering.
ActorSystem joined a cluster.ActorSystem is connected to a clusterActorSystem just started has not joined a cluster.Tags: [ "akka", "ready", "cluster" ]
AkkaClusterLivenessProbe - Liveness probe for clustering.
ActorSystem joined a cluster.ActorSystem is connected to a clusterActorSystem just started and has not joined a cluster.ActorSystem left the cluster.Tags: [ "akka", "live", "cluster" ]
AkkaPersistenceLivenessProbe - Liveness probe for persistence. It probes the persistence storage every second to check that persistence is working properly.
Tags: [ "akka", "live", "persistence" ]
There are 3 steps that needs to be done to integrate Akka.HealthCheck with diagnostic health check
Akka.HealthCheck to the ActorSystem.Akka.HealthCheck Services With HealthCheckThe convenience IServiceCollection extension method WithAkkaHealthCheck(HealthCheckType) can be used to register the standard probes in any combination.
var webBuilder = WebApplication.CreateBuilder(args);
webBuilder.Services
.WithAkkaHealthCheck(HealthCheckType.All);
As alternative, individual probes can be registered using these methods:
WithAkkaLivenessProbe()WithAkkaReadinessProbe()WithAkkaClusterLivenessProbe()WithAkkaClusterReadinessProbe()WithAkkaPersistenceLivenessProbe()Akka.HealthCheck To The ActorSystemThe convenience AkkaConfigurationBuilder extension method WithWebHealthCheck(IServiceProvider) automatically scans for any registered probes inside the health check middleware and adds the respective Akka.NET health check probes to the ActorSystem
var webBuilder = WebApplication.CreateBuilder(args);
webBuilder.Services
.WithAkkaHealthCheck(HealthCheckType.All)
.AddAkka("actor-system", (builder, serviceProvider) =>
{
// Automatically detects which health checks were registered
// inside the health check middleware and starts them
builder.WithWebHealthCheck(serviceProvider);
});
The convenience IEndpointRouteBuilder extension method MapAkkaHealthCheckRoutes automatically scans for any registered probes inside the health check middleware and maps all the probes to a HTTP route. The HTTP route is the concatenation of the probe tags. By default:
AkkaReadinessProbe is mapped to "/{prefix}/akka/ready/node"AkkaLivenessProbe is mapped to "/{prefix}/akka/live/node"AkkaClusterReadinessProbe is mapped to "/{prefix}/akka/ready/cluster"AkkaClusterLivenessProbe is mapped to "/{prefix}/akka/live/cluster"AkkaPersistenceLivenessProbe is mapped to "/{prefix}/akka/live/persistence"var webBuilder = WebApplication.CreateBuilder(args);
webBuilder.Services
// Register all of the health check service with IServiceCollection
.WithAkkaHealthCheck(HealthCheckType.All)
.AddAkka("actor-system", (builder, serviceProvider) =>
{
builder
// Automatically detects which health checks were registered
// inside the health check middleware and starts them
.WithWebHealthCheck(serviceProvider);
});
var app = webBuilder.Build();
// Automatically detects which health checks were registered inside
// the health check middleware and maps their routes
app.MapAkkaHealthCheckRoutes();
await app.RunAsync();
By default, the health check middleware outputs a simple string response of either "healthy" or "unhealthy" regardless of the number of probes being queried. To more verbose response can be gained by using Helper.JsonResponseWriter as the route endpoint response writer.
app.MapAkkaHealthCheckRoutes(
optionConfigure: opt =>
{
// Use a custom response writer to output a json of all reported statuses
opt.ResponseWriter = Helper.JsonResponseWriter;
});
Example output when all probes are enabled:
{
"status": "Healthy",
"results": {
"akka-liveness": {
"status": "Healthy",
"description": "Akka.NET node is alive",
"data": {
"message": "Live: 12/16/2022 9:54:28 PM +00:00"
}
},
"akka-readiness": {
"status": "Healthy",
"description": "Akka.NET node is ready",
"data": {
"message": "Live: 12/16/2022 9:54:28 PM +00:00"
}
},
"akka-cluster-liveness": {
"status": "Healthy",
"description": "Akka.NET cluster is alive",
"data": {
"message": ""
}
},
"akka-cluster-readiness": {
"status": "Healthy",
"description": "Akka.NET cluster is ready",
"data": {
"message": ""
}
},
"akka-persistence-liveness": {
"status": "Healthy",
"description": "Akka.NET persistence is alive",
"data": {
"message": "RecoveryStatus(JournalRecovered=True, SnapshotRecovered=True)"
}
}
}
}
IProbeProvider With Health Check MiddlewareTo manually setup a custom IProbeProvider, check the custom probe example project.
Documentation on how to set up ASP.NET Core health check can be read here
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.1 netcoreapp3.1 is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
[Bump Akka version to 1.5.37](https://github.com/akkadotnet/akka.net/releases/tag/1.5.37)
[Bump Akka.Hosting to 1.5.37](https://github.com/akkadotnet/Akka.Hosting/releases/tag/1.5.37)