Add loopback health and Prometheus metrics endpoint
All checks were successful
CI / check (push) Successful in 4m22s
All checks were successful
CI / check (push) Successful in 4m22s
This commit is contained in:
parent
381f706634
commit
ad8a3fe065
6 changed files with 180 additions and 0 deletions
|
|
@ -935,6 +935,12 @@ impl EventLog {
|
|||
self.entries.len()
|
||||
}
|
||||
|
||||
// The highest Lamport clock seen. Monotonic across compaction (unlike `len`,
|
||||
// which a snapshot shrinks), so it's the gauge that shows the log advancing.
|
||||
fn lamport(&self) -> u64 {
|
||||
self.lamport
|
||||
}
|
||||
|
||||
// Rewrite the log to a minimal snapshot: one event per live account and
|
||||
// channel, authored under our origin at fresh sequence numbers. Peers
|
||||
// re-converge because the register events overwrite and cert replay is
|
||||
|
|
@ -1366,6 +1372,12 @@ impl Db {
|
|||
self.log.len()
|
||||
}
|
||||
|
||||
/// The highest Lamport clock committed — a monotonic gauge of log progress
|
||||
/// (survives compaction), for the health/metrics endpoint.
|
||||
pub fn lamport(&self) -> u64 {
|
||||
self.log.lamport()
|
||||
}
|
||||
|
||||
/// The events appended since `mark` (a value from an earlier [`log_len`]).
|
||||
pub fn events_since(&self, mark: usize) -> Vec<Event> {
|
||||
self.log.events_from(mark)
|
||||
|
|
|
|||
|
|
@ -295,6 +295,18 @@ impl Engine {
|
|||
m
|
||||
}
|
||||
|
||||
// The stat snapshot plus event-log position, for the health/metrics endpoint.
|
||||
// The log gauges (seq/lamport/entries) let a monitor watch replication progress
|
||||
// and catch a stalled or non-advancing log before users notice.
|
||||
pub fn health_metrics(&self) -> std::collections::BTreeMap<String, u64> {
|
||||
let mut m = self.stats_snapshot();
|
||||
// lamport is monotonic (survives compaction) — the "log advancing" gauge;
|
||||
// entries is the current in-memory log size (drops at each compaction).
|
||||
m.insert("event.lamport".to_string(), self.db.lamport());
|
||||
m.insert("log.entries".to_string(), self.db.log_len() as u64);
|
||||
m
|
||||
}
|
||||
|
||||
// Snapshot the accumulated stat counters to the log (periodically and on
|
||||
// shutdown) so StatServ / the Stats API keep their history across a restart.
|
||||
// Only the real counters are persisted; the live gauges above are re-derived.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue