Skip to content

Commit

Permalink
agent: add server raft.{last,applied}_index gauges (#6694)
Browse files Browse the repository at this point in the history
These metrics are useful for :
* Tracking the rate of update to the db
* Allow to have a rough idea of when an index originated
  • Loading branch information
ShimmerGlass authored Feb 11, 2020
1 parent 895a8a4 commit 68e0f6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 6 additions & 4 deletions agent/consul/session_ttl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 68e0f6b

Please sign in to comment.