Class RaftMetrics
java.lang.Object
com.loomcache.server.consensus.RaftMetrics
Raft consensus node performance metrics.
Purpose: Tracks and exposes metrics for Raft operations including elections, log replication, commits, and snapshots. All metrics are thread-safe using AtomicLong and LongAdder, making them suitable for low-contention concurrent access.
Thread Safety: All metric operations are thread-safe and lock-free. Multiple threads can safely record metrics concurrently without synchronization.
Use Cases:
- Monitor Raft consensus health and performance
- Track replication latency and success rates
- Detect issues with leader elections or log consistency
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordImmutable snapshot of Raft metrics at a point in time. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleGet average latency for AppendEntries RPC in milliseconds.longGet total AppendEntries RPC count.doubleGet average latency for commit in milliseconds.longGet total commit count.longGet total number of elections.longGet current log size in entries.Return a snapshot of all metrics at a point in time.longGet total number of snapshots.longGet total number of term changes.longGet count of uncommitted entries.voidrecordAppendEntries(long latencyMs) Record an AppendEntries RPC with latency in milliseconds.voidrecordCommit(long latencyMs) Record a commit operation with latency in milliseconds.voidRecord an election event.voidRecord a snapshot operation.voidRecord a term change.voidsetLogSize(long size) Set the current log size.voidsetUncommittedEntries(long count) Set the number of uncommitted entries.
-
Constructor Details
-
RaftMetrics
public RaftMetrics()
-
-
Method Details
-
recordElection
public void recordElection()Record an election event. -
recordAppendEntries
public void recordAppendEntries(long latencyMs) Record an AppendEntries RPC with latency in milliseconds.- Parameters:
latencyMs- the round-trip latency in milliseconds (must be non-negative)
-
recordCommit
public void recordCommit(long latencyMs) Record a commit operation with latency in milliseconds.- Parameters:
latencyMs- the operation latency in milliseconds (must be non-negative)
-
setLogSize
public void setLogSize(long size) Set the current log size.- Parameters:
size- the number of entries in the log (must be non-negative)
-
setUncommittedEntries
public void setUncommittedEntries(long count) Set the number of uncommitted entries.- Parameters:
count- the count of uncommitted entries (must be non-negative)
-
recordTermChange
public void recordTermChange()Record a term change. -
recordSnapshot
public void recordSnapshot()Record a snapshot operation. -
getElectionCount
public long getElectionCount()Get total number of elections. -
getAppendEntriesAvgLatency
public double getAppendEntriesAvgLatency()Get average latency for AppendEntries RPC in milliseconds. -
getCommitAvgLatency
public double getCommitAvgLatency()Get average latency for commit in milliseconds. -
getLogSize
public long getLogSize()Get current log size in entries. -
getUncommittedEntries
public long getUncommittedEntries()Get count of uncommitted entries. -
getTermChanges
public long getTermChanges()Get total number of term changes. -
getSnapshotCount
public long getSnapshotCount()Get total number of snapshots. -
getAppendEntriesCount
public long getAppendEntriesCount()Get total AppendEntries RPC count. -
getCommitCount
public long getCommitCount()Get total commit count. -
getMetrics
Return a snapshot of all metrics at a point in time.- Returns:
- a MetricsSnapshot with all current metric values (never null)
-