consul: Collect useful session metrics
This commit is contained in:
parent
096ff61121
commit
6b9ace19cf
|
@ -257,6 +257,9 @@ func NewServer(config *Config) (*Server, error) {
|
|||
|
||||
// Start listening for RPC requests
|
||||
go s.listen()
|
||||
|
||||
// Start the metrics handlers
|
||||
go s.sessionStats()
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,7 @@ func (s *Session) Renew(args *structs.SessionSpecificRequest,
|
|||
if done, err := s.srv.forward("Session.Renew", args, args, reply); done {
|
||||
return err
|
||||
}
|
||||
defer metrics.MeasureSince([]string{"consul", "session", "renew"}, time.Now())
|
||||
|
||||
// Get the session, from local state
|
||||
state := s.srv.fsm.State()
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/armon/go-metrics"
|
||||
"github.com/hashicorp/consul/consul/structs"
|
||||
)
|
||||
|
||||
|
@ -95,6 +96,7 @@ func (s *Server) resetSessionTimerLocked(id string, ttl time.Duration) {
|
|||
// invalidateSession is invoked when a session TTL is reached and we
|
||||
// need to invalidate the session.
|
||||
func (s *Server) invalidateSession(id string) {
|
||||
defer metrics.MeasureSince([]string{"consul", "session_ttl", "invalidate"}, time.Now())
|
||||
// Clear the session timer
|
||||
s.sessionTimersLock.Lock()
|
||||
delete(s.sessionTimers, id)
|
||||
|
@ -142,3 +144,20 @@ func (s *Server) clearAllSessionTimers() error {
|
|||
s.sessionTimers = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// sessionStats is a long running routine used to capture
|
||||
// the number of active sessions being tracked
|
||||
func (s *Server) sessionStats() {
|
||||
for {
|
||||
select {
|
||||
case <-time.After(5 * time.Second):
|
||||
s.sessionTimersLock.Lock()
|
||||
num := len(s.sessionTimers)
|
||||
s.sessionTimersLock.Unlock()
|
||||
metrics.SetGauge([]string{"consul", "session_ttl", "active"}, float32(num))
|
||||
|
||||
case <-s.shutdownCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue