⚠ Deprecated: Legacy
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.
Suggested alternative: Akka.Hosting
Package Description
$ dotnet add package Akka.HealthCheck.Hosting.WebThis 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