Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Akka.Cluster HTTP HealthCheck
public class HomeController : Controller
{
private readonly Cluster _cluster;
public HomeController()
{
_cluster = Cluster.Get(SystemActors.ActorSystem);
}
public IActionResult Index()
{
return View();
}
public IActionResult HealthCheck()
{
var state = _cluster.State;
var atLeastOneAvailableLighthouse = state.Members
.Any(x => x.HasRole("lighthouse")
&& x.Status == MemberStatus.Up
&& !state.Unreachable.Contains(x));
var statusCode = atLeastOneAvailableLighthouse
? HttpStatusCode.OK
: HttpStatusCode.InternalServerError;
var sb = new StringBuilder();
sb.AppendLine("Members: ");
foreach (var member in state.Members)
{
sb.AppendFormat("{0}[{1}] Roles=[{2}], Reachable={3}", member.Address, member.Status,
string.Join(",", member.Roles), !state.Unreachable.Contains(member));
sb.AppendLine();
}
return new ContentResult()
{
Content = sb.ToString(),
StatusCode = (int) statusCode
};
}
}
@Aaronontheweb

This comment has been minimized.

Copy link
Owner Author

@Aaronontheweb Aaronontheweb commented May 14, 2018

Basic internal HTTP healthcheck for determining if we're in a joinable cluster, via the "at least one reachable lighthouse node is a current member of the cluster" rule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.