forked from couchbaselabs/cbgb
/
store_stats.go
77 lines (66 loc) · 2.76 KB
/
store_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"sync/atomic"
)
type BucketStoreStats struct {
Time int64 `json:"time"`
Flushes int64 `json:"flushes"`
Reads int64 `json:"reads"`
Writes int64 `json:"writes"`
Stats int64 `json:"stats"`
Compacts int64 `json:"compacts"`
LastCompactAt int64 `json:"lastCompactAt"`
FlushErrors int64 `json:"flushErrors"`
ReadErrors int64 `json:"readErrors"`
WriteErrors int64 `json:"writeErrors"`
StatErrors int64 `json:"statErrors"`
CompactErrors int64 `json:"compactErrors"`
ReadBytes int64 `json:"readBytes"`
WriteBytes int64 `json:"writeBytes"`
FileSize int64 `json:"fileSize"`
NodeAllocs int64 `json:"nodeAllocs"`
}
func (bss *BucketStoreStats) Add(in *BucketStoreStats) {
bss.Op(in, addInt64)
}
func (bss *BucketStoreStats) Sub(in *BucketStoreStats) {
bss.Op(in, subInt64)
}
func (bss *BucketStoreStats) Op(in *BucketStoreStats, op func(int64, int64) int64) {
bss.Flushes = op(bss.Flushes, atomic.LoadInt64(&in.Flushes))
bss.Reads = op(bss.Reads, atomic.LoadInt64(&in.Reads))
bss.Writes = op(bss.Writes, atomic.LoadInt64(&in.Writes))
bss.Stats = op(bss.Stats, atomic.LoadInt64(&in.Stats))
bss.Compacts = op(bss.Compacts, atomic.LoadInt64(&in.Compacts))
bss.FlushErrors = op(bss.FlushErrors, atomic.LoadInt64(&in.FlushErrors))
bss.ReadErrors = op(bss.ReadErrors, atomic.LoadInt64(&in.ReadErrors))
bss.WriteErrors = op(bss.WriteErrors, atomic.LoadInt64(&in.WriteErrors))
bss.StatErrors = op(bss.StatErrors, atomic.LoadInt64(&in.StatErrors))
bss.CompactErrors = op(bss.CompactErrors, atomic.LoadInt64(&in.CompactErrors))
bss.ReadBytes = op(bss.ReadBytes, atomic.LoadInt64(&in.ReadBytes))
bss.WriteBytes = op(bss.WriteBytes, atomic.LoadInt64(&in.WriteBytes))
bss.FileSize = op(bss.FileSize, atomic.LoadInt64(&in.FileSize))
bss.NodeAllocs = op(bss.NodeAllocs, atomic.LoadInt64(&in.NodeAllocs))
}
func (bss *BucketStoreStats) Aggregate(in Aggregatable) {
if in == nil {
return
}
bss.Add(in.(*BucketStoreStats))
}
func (bss *BucketStoreStats) Equal(in *BucketStoreStats) bool {
return bss.Flushes == atomic.LoadInt64(&in.Flushes) &&
bss.Reads == atomic.LoadInt64(&in.Reads) &&
bss.Writes == atomic.LoadInt64(&in.Writes) &&
bss.Stats == atomic.LoadInt64(&in.Stats) &&
bss.Compacts == atomic.LoadInt64(&in.Compacts) &&
bss.FlushErrors == atomic.LoadInt64(&in.FlushErrors) &&
bss.ReadErrors == atomic.LoadInt64(&in.ReadErrors) &&
bss.WriteErrors == atomic.LoadInt64(&in.WriteErrors) &&
bss.StatErrors == atomic.LoadInt64(&in.StatErrors) &&
bss.CompactErrors == atomic.LoadInt64(&in.CompactErrors) &&
bss.ReadBytes == atomic.LoadInt64(&in.ReadBytes) &&
bss.WriteBytes == atomic.LoadInt64(&in.WriteBytes) &&
bss.FileSize == atomic.LoadInt64(&in.FileSize) &&
bss.NodeAllocs == atomic.LoadInt64(&in.NodeAllocs)
}