summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2020-09-08 21:36:30 +0300
committerPaul Buetow <pbuetow@mimecast.com>2020-09-08 21:36:30 +0300
commit40cbef0c243042521bdf589b3c4549ff32508592 (patch)
tree1a996d70d02bcb425edd48b8f3c2f32af8f6b303 /internal
parent3a7b359055f4277d3a07b3b7bf8580ef575c54a8 (diff)
refactor
Diffstat (limited to 'internal')
-rw-r--r--internal/clients/stats.go36
1 files changed, 16 insertions, 20 deletions
diff --git a/internal/clients/stats.go b/internal/clients/stats.go
index ec6adfe..481d157 100644
--- a/internal/clients/stats.go
+++ b/internal/clients/stats.go
@@ -5,7 +5,6 @@ import (
"fmt"
"runtime"
"sync"
- "time"
"github.com/mimecast/dtail/internal/io/logger"
)
@@ -30,13 +29,12 @@ func newTailStats(connectionsTotal int) *stats {
}
}
-func (s *stats) periodicLogStats(ctx context.Context, throttleCh chan struct{}) {
- connectedLast := 0
- statsInterval := 5
+func (s *stats) logStatsOnSignal(ctx context.Context, throttleCh chan struct{}, sigCh chan struct{}) {
+ var connectedLast int
for {
select {
- case <-time.After(time.Second * time.Duration(statsInterval)):
+ case <-sigCh:
case <-ctx.Done():
return
}
@@ -45,34 +43,32 @@ func (s *stats) periodicLogStats(ctx context.Context, throttleCh chan struct{})
throttle := len(throttleCh)
newConnections := connected - connectedLast
- connectionsPerSecond := float64(newConnections) / float64(statsInterval)
- s.log(connected, newConnections, connectionsPerSecond, throttle)
-
- connectedLast = connected
+ s.log(connected, newConnections, throttle)
s.mutex.Lock()
+ defer s.mutex.Unlock()
+
+ connectedLast = connected
s.connected = connected
- s.mutex.Unlock()
}
}
-func (s *stats) numConnected() int {
- s.mutex.Lock()
- defer s.mutex.Unlock()
-
- return s.connected
-}
-
-func (s *stats) log(connected, newConnections int, connectionsPerSecond float64, throttle int) {
+func (s *stats) log(connected, newConnections int, throttle int) {
percConnected := percentOf(float64(s.connectionsTotal), float64(connected))
connectedStr := fmt.Sprintf("connected=%d/%d(%d%%)", connected, s.connectionsTotal, int(percConnected))
newConnStr := fmt.Sprintf("new=%d", newConnections)
- rateStr := fmt.Sprintf("rate=%2.2f/s", connectionsPerSecond)
throttleStr := fmt.Sprintf("throttle=%d", throttle)
cpusGoroutinesStr := fmt.Sprintf("cpus/goroutines=%d/%d", runtime.NumCPU(), runtime.NumGoroutine())
- logger.Info("stats", connectedStr, newConnStr, rateStr, throttleStr, cpusGoroutinesStr)
+ logger.Info("stats", connectedStr, newConnStr, throttleStr, cpusGoroutinesStr)
+}
+
+func (s *stats) numConnected() int {
+ s.mutex.Lock()
+ defer s.mutex.Unlock()
+
+ return s.connected
}
func percentOf(total float64, value float64) float64 {