Interface ElectionMetrics


public interface ElectionMetrics
Metrics about leader election and leadership stability.

Provides information about the current leader, when the last election took place, and how long the current leader has been in charge. These metrics are useful for detecting leadership instability; frequent elections suggest network problems or misconfigured failure detectors, and each election causes an unavailability window where the cluster cannot accept operations.

Node-Local Perspective

Election metrics reflect each node's local view. Nodes learn about a new leader at different times depending on when they receive the leader-elected message, so timestamps and durations may vary across the cluster. Only the JGroups coordinator runs the election process; on other nodes, some values may return defaults (null or -1) until the first election result is received.

Since:
2.0
Author:
José Bolina
  • Method Details

    • getLeaderRaftId

      String getLeaderRaftId()
      The Raft identifier of the current leader.

      Use this to route client requests or to verify that a specific node holds leadership. The value updates when this node learns about a new leader, which may happen after the election completes on the coordinator.

      Returns:
      the leader's Raft ID, or a null string if no leader is known or metrics are disabled.
    • getLeaderElectionTime

      Instant getLeaderElectionTime()
      The instant at which the last leader election started, as observed by this node.

      On the JGroups coordinator, this reflects when the voting process began. On other nodes, it returns null, since the non-coordinator nodes do not start the voting process. Compare consecutive values to measure election frequency; elections happening frequently indicate cluster instability.

      Returns:
      the election start time, or null if no election has occurred yet. Returns Instant.EPOCH when metrics are disabled.
    • getTimeSinceLastLeaderChange

      Duration getTimeSinceLastLeaderChange()
      The time elapsed since the last leader election ended.

      A steadily growing value indicates a stable leader. If this value stays small or resets frequently, the cluster is experiencing repeated elections, which impacts availability. Use this metric to set up alerts when leadership tenure falls below an expected threshold.

      Returns:
      the duration since the last election ended, or Duration.ZERO if no election has completed or metrics are disabled.