-
Notifications
You must be signed in to change notification settings - Fork 3
/
stats.go
54 lines (46 loc) · 875 Bytes
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package mongogo
import (
"sync"
)
var stats *Stats
var statsMutex sync.Mutex
func SetCollectStats(enabled bool) {
statsMutex.Lock()
if enabled {
if stats == nil {
stats = &Stats{}
}
} else {
stats = nil
}
statsMutex.Unlock()
}
func GetStats() (snapshot Stats) {
statsMutex.Lock()
snapshot = *stats
statsMutex.Unlock()
return
}
func ResetStats() {
statsMutex.Lock()
stats = &Stats{}
statsMutex.Unlock()
return
}
type Stats struct {
MasterConns int
SlaveConns int
BytesWritten int
BytesRead int
}
func (stats *Stats) trackConn(delta int, master bool) {
if stats != nil {
statsMutex.Lock()
if master {
stats.MasterConns += delta
} else {
stats.SlaveConns += delta
}
statsMutex.Unlock()
}
}