mirror of
https://github.com/go-gost/core.git
synced 2026-10-19 16:16:17 +00:00
observer: add Reset for stats
This commit is contained in:
+11
-2
@@ -19,7 +19,7 @@ const (
|
||||
type Stats struct {
|
||||
updated atomic.Bool
|
||||
totalConns atomic.Uint64
|
||||
currentConns atomic.Int64
|
||||
currentConns atomic.Uint64
|
||||
inputBytes atomic.Uint64
|
||||
outputBytes atomic.Uint64
|
||||
totalErrs atomic.Uint64
|
||||
@@ -35,7 +35,7 @@ func (s *Stats) Add(kind Kind, n int64) {
|
||||
s.totalConns.Add(uint64(n))
|
||||
}
|
||||
case KindCurrentConns:
|
||||
s.currentConns.Add(n)
|
||||
s.currentConns.Add(uint64(n))
|
||||
case KindInputBytes:
|
||||
if n > 0 {
|
||||
s.inputBytes.Add(uint64(n))
|
||||
@@ -72,6 +72,15 @@ func (s *Stats) Get(kind Kind) uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *Stats) Reset() {
|
||||
s.updated.Store(false)
|
||||
s.totalConns.Store(0)
|
||||
s.currentConns.Store(0)
|
||||
s.inputBytes.Store(0)
|
||||
s.outputBytes.Store(0)
|
||||
s.totalErrs.Store(0)
|
||||
}
|
||||
|
||||
func (s *Stats) IsUpdated() bool {
|
||||
return s.updated.Swap(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user