Initial v1.1.8 Commits
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Stats struct {
|
||||
ActiveConnections int32
|
||||
Reconnects int64
|
||||
TotalBytesUp int64
|
||||
TotalBytesDown int64
|
||||
CredsErrors int64
|
||||
}
|
||||
|
||||
func NewStats() *Stats {
|
||||
return &Stats{}
|
||||
}
|
||||
|
||||
func (s *Stats) RunLoop(shutdown <-chan struct{}) {
|
||||
ticker := time.NewTicker(3 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-shutdown:
|
||||
return
|
||||
case <-ticker.C:
|
||||
active := atomic.LoadInt32(&s.ActiveConnections)
|
||||
up := atomic.LoadInt64(&s.TotalBytesUp)
|
||||
down := atomic.LoadInt64(&s.TotalBytesDown)
|
||||
totalMB := float64(up+down) / (1024.0 * 1024.0)
|
||||
|
||||
log.Printf("[СТАТИСТИКА] Активных: %d | Трафик: %.2f МБ", active, totalMB)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user