Class Health
Health health = admin.health();
if (!health.alarms().isOk()) {
log.error("broker is refusing publishes: {}", health.alarms().reason().orElse(""));
}
Why these rather than metrics
An alert built on the metrics endpoint infers health from numbers. These endpoints are the
broker answering the question itself, and two of them have no metric equivalent at all:
quorumCritical() knows which quorum queues would lose their majority if one more node
went away, and certificateExpiration(int, String) knows when your TLS certificates
expire. No amount of scraping produces either.
Not for a load balancer's readiness probe
alarms() and quorumCritical() are cluster-wide, so every node answers
identically and a load balancer using them takes the whole cluster out at once. For a probe,
isInService() or localAlarms() — both node-local — are the ones that make a
single unhealthy node stop receiving traffic while the rest keep serving.
-
Method Summary
Modifier and TypeMethodDescriptionalarms()certificateExpiration(int within, String unit) Whether any TLS certificate expires within the given window.checkAll()Runs the checks that need no arguments and apply to any broker.failures()booleanportListener(int port) protocolListener(String protocol) Whether any quorum queue would lose its majority if one more node went down.
-
Method Details
-
alarms
- Returns:
- whether any resource alarm is in effect anywhere in the cluster. While one is, publishers are blocked
-
localAlarms
- Returns:
- whether a resource alarm is in effect on this node. The one to use
for a per-node probe, because
alarms()fails on every node at once
-
quorumCritical
Whether any quorum queue would lose its majority if one more node went down.No metric reports this. It is also the check that decides whether a rolling restart may continue: proceeding while it fails is how a cluster loses quorum on queues that were one node away from it.
- Returns:
- the result
-
isInService
- Returns:
- whether this node is fully started and not being drained for maintenance
-
readyToServeClients
- Returns:
- whether every protocol listener is up and the node will accept clients
-
virtualHosts
- Returns:
- whether every virtual host on this node is running
-
belowNodeConnectionLimit
- Returns:
- whether the node is below its configured connection limit
-
portListener
- Parameters:
port- a TCP port, for example 5672- Returns:
- whether something is listening on it
-
protocolListener
- Parameters:
protocol-amqp,amqps,mqtt,stomp,http- Returns:
- whether a listener for it is running
-
certificateExpiration
Whether any TLS certificate expires within the given window.The check nobody has until the morning a certificate expires. It has no metric, and it is the only one here that is about the future rather than the present.
- Parameters:
within- how many units ahead to lookunit-days,weeks,monthsoryears- Returns:
- the result
-
checkAll
Runs the checks that need no arguments and apply to any broker.Deliberately excludes
portListener(int),protocolListener(String)andcertificateExpiration(int, String), which need to be told what to look for, andalarms(), which duplicateslocalAlarms()across the cluster.- Returns:
- every result, passing and failing
-
isHealthy
public boolean isHealthy()- Returns:
- whether every check in
checkAll()passed
-
failures
- Returns:
- the checks in
checkAll()that failed, which is the list worth printing
-