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
This commit is contained in:
ShimmerGlass 2020-02-11 10:50:18 +01:00 committed by GitHub
parent 1c88dc15ef
commit a27ccc7248
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -543,7 +543,7 @@ func NewServerLogger(config *Config, logger hclog.InterceptLogger, tokens *token
} }
// Start the metrics handlers. // Start the metrics handlers.
go s.sessionStats() go s.updateMetrics()
return s, nil return s, nil
} }

View File

@ -130,14 +130,16 @@ func (s *Server) clearAllSessionTimers() {
s.sessionTimers.StopAll() s.sessionTimers.StopAll()
} }
// sessionStats is a long running routine used to capture // updateMetrics is a long running routine used to uddate a
// the number of active sessions being tracked // number of server periodic metrics
func (s *Server) sessionStats() { func (s *Server) updateMetrics() {
for { for {
select { 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{"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: case <-s.shutdownCh:
return return
} }