From 68e0f6bf84a411cce49e9392e3dbb020a9c146b6 Mon Sep 17 00:00:00 2001 From: ShimmerGlass Date: Tue, 11 Feb 2020 10:50:18 +0100 Subject: [PATCH] agent: add server raft.{last,applied}_index gauges (#6694) These metrics are useful for : * Tracking the rate of update to the db * Allow to have a rough idea of when an index originated --- agent/consul/server.go | 2 +- agent/consul/session_ttl.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/agent/consul/server.go b/agent/consul/server.go index 4b592ac944..579eedab45 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -543,7 +543,7 @@ func NewServerLogger(config *Config, logger hclog.InterceptLogger, tokens *token } // Start the metrics handlers. - go s.sessionStats() + go s.updateMetrics() return s, nil } diff --git a/agent/consul/session_ttl.go b/agent/consul/session_ttl.go index 94c6409ce9..4afdc0e382 100644 --- a/agent/consul/session_ttl.go +++ b/agent/consul/session_ttl.go @@ -130,14 +130,16 @@ func (s *Server) clearAllSessionTimers() { s.sessionTimers.StopAll() } -// sessionStats is a long running routine used to capture -// the number of active sessions being tracked -func (s *Server) sessionStats() { +// updateMetrics is a long running routine used to uddate a +// number of server periodic metrics +func (s *Server) updateMetrics() { for { select { - case <-time.After(5 * time.Second): + case <-time.After(time.Second): metrics.SetGauge([]string{"session_ttl", "active"}, float32(s.sessionTimers.Len())) + metrics.SetGauge([]string{"raft", "applied_index"}, float32(s.raft.AppliedIndex())) + metrics.SetGauge([]string{"raft", "last_index"}, float32(s.raft.LastIndex())) case <-s.shutdownCh: return }