diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-09-10 14:57:52 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-09-10 14:57:52 +0100 |
| commit | 1c7c0dbb5174b5255912183b9ec5870ccdef3426 (patch) | |
| tree | 50a5e492ac42221178320fb06a16c34e1b0a4bba /internal/clients/stats.go | |
| parent | 40cbef0c243042521bdf589b3c4549ff32508592 (diff) | |
printing client stats every other second only if the connection count has changed or when SIGUSR1 or SIGINFO recieved
Diffstat (limited to 'internal/clients/stats.go')
| -rw-r--r-- | internal/clients/stats.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/internal/clients/stats.go b/internal/clients/stats.go index 481d157..a6ac0c5 100644 --- a/internal/clients/stats.go +++ b/internal/clients/stats.go @@ -5,6 +5,7 @@ import ( "fmt" "runtime" "sync" + "time" "github.com/mimecast/dtail/internal/io/logger" ) @@ -29,12 +30,18 @@ func newTailStats(connectionsTotal int) *stats { } } -func (s *stats) logStatsOnSignal(ctx context.Context, throttleCh chan struct{}, sigCh chan struct{}) { +// Start starts printing client connection stats every time a signal is recieved or +// connection count has changed. +func (s *stats) Start(ctx context.Context, throttleCh, statsCh <-chan struct{}) { var connectedLast int for { + var force bool + select { - case <-sigCh: + case <-statsCh: + force = true + case <-time.After(time.Second * 2): case <-ctx.Done(): return } @@ -43,13 +50,16 @@ func (s *stats) logStatsOnSignal(ctx context.Context, throttleCh chan struct{}, throttle := len(throttleCh) newConnections := connected - connectedLast - s.log(connected, newConnections, throttle) - s.mutex.Lock() - defer s.mutex.Unlock() + if connected == connectedLast && !force { + continue + } + s.log(connected, newConnections, throttle) connectedLast = connected + s.mutex.Lock() s.connected = connected + s.mutex.Unlock() } } |
