summaryrefslogtreecommitdiff
path: root/internal/server/stats.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/server/stats.go')
-rw-r--r--internal/server/stats.go21
1 files changed, 9 insertions, 12 deletions
diff --git a/internal/server/stats.go b/internal/server/stats.go
index ac579ad..99a644a 100644
--- a/internal/server/stats.go
+++ b/internal/server/stats.go
@@ -3,12 +3,11 @@ package server
import (
"context"
"fmt"
- "runtime"
"sync"
"time"
"github.com/mimecast/dtail/internal/config"
- "github.com/mimecast/dtail/internal/io/logger"
+ "github.com/mimecast/dtail/internal/io/dlog"
)
// Used to collect and display various server stats.
@@ -20,7 +19,6 @@ type stats struct {
func (s *stats) incrementConnections() {
defer s.logServerStats()
-
s.mutex.Lock()
s.currentConnections++
s.lifetimeConnections++
@@ -29,7 +27,6 @@ func (s *stats) incrementConnections() {
func (s *stats) decrementConnections() {
defer s.logServerStats()
-
s.mutex.Lock()
s.currentConnections--
s.mutex.Unlock()
@@ -41,8 +38,8 @@ func (s *stats) hasConnections() bool {
s.mutex.Unlock()
has := currentConnections > 0
- logger.Info("stats", "Server with open connections?", has, currentConnections)
-
+ dlog.Server.Info("stats", "Server with open connections?",
+ has, currentConnections)
return has
}
@@ -50,10 +47,10 @@ func (s *stats) logServerStats() {
s.mutex.Lock()
defer s.mutex.Unlock()
- currentConnections := fmt.Sprintf("currentConnections=%d", s.currentConnections)
- lifetimeConnections := fmt.Sprintf("lifetimeConnections=%d", s.lifetimeConnections)
- goroutines := fmt.Sprintf("goroutines=%d", runtime.NumGoroutine())
- logger.Info("stats", currentConnections, lifetimeConnections, goroutines)
+ data := make(map[string]interface{})
+ data["currentConnections"] = s.currentConnections
+ data["lifetimeConnections"] = s.lifetimeConnections
+ dlog.Server.Mapreduce("STATS", data)
}
func (s *stats) serverLimitExceeded() error {
@@ -61,9 +58,9 @@ func (s *stats) serverLimitExceeded() error {
defer s.mutex.Unlock()
if s.currentConnections >= config.Server.MaxConnections {
- return fmt.Errorf("Exceeded max allowed concurrent connections of %d", config.Server.MaxConnections)
+ return fmt.Errorf("Exceeded max allowed concurrent connections of %d",
+ config.Server.MaxConnections)
}
-
return nil
}