Class Health

java.lang.Object
org.acemq.rabbitmq.admin.Health

public final class Health extends Object
The broker's own health checks.

 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 Details

    • alarms

      public HealthResult alarms()
      Returns:
      whether any resource alarm is in effect anywhere in the cluster. While one is, publishers are blocked
    • localAlarms

      public HealthResult 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

      public HealthResult 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

      public HealthResult isInService()
      Returns:
      whether this node is fully started and not being drained for maintenance
    • readyToServeClients

      public HealthResult readyToServeClients()
      Returns:
      whether every protocol listener is up and the node will accept clients
    • virtualHosts

      public HealthResult virtualHosts()
      Returns:
      whether every virtual host on this node is running
    • belowNodeConnectionLimit

      public HealthResult belowNodeConnectionLimit()
      Returns:
      whether the node is below its configured connection limit
    • portListener

      public HealthResult portListener(int port)
      Parameters:
      port - a TCP port, for example 5672
      Returns:
      whether something is listening on it
    • protocolListener

      public HealthResult protocolListener(String protocol)
      Parameters:
      protocol - amqp, amqps, mqtt, stomp, http
      Returns:
      whether a listener for it is running
    • certificateExpiration

      public HealthResult certificateExpiration(int within, String unit)
      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 look
      unit - days, weeks, months or years
      Returns:
      the result
    • checkAll

      public List<HealthResult> checkAll()
      Runs the checks that need no arguments and apply to any broker.

      Deliberately excludes portListener(int), protocolListener(String) and certificateExpiration(int, String), which need to be told what to look for, and alarms(), which duplicates localAlarms() across the cluster.

      Returns:
      every result, passing and failing
    • isHealthy

      public boolean isHealthy()
      Returns:
      whether every check in checkAll() passed
    • failures

      public List<HealthResult> failures()
      Returns:
      the checks in checkAll() that failed, which is the list worth printing