-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
78 lines (60 loc) · 1.96 KB
/
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
78
package gloader
import (
"github.com/mohammadv184/gloader/data"
"github.com/mohammadv184/gloader/pkg/stats"
)
type MetricKey string
func (m MetricKey) String() string {
return string(m)
}
const (
MetricBufferSizeBytes MetricKey = "buffer.size.bytes"
MetricBufferLengthRows MetricKey = "buffer.length.rows"
MetricBufferTotalWriteLengthRows MetricKey = "buffer.totalWriteLength.rows"
MetricBufferTotalReadLengthRows MetricKey = "buffer.totalReadLength.rows"
)
type BufferObserverAdapter struct {
s *stats.Stats
dcName string
}
var _ data.BufferObserver = &BufferObserverAdapter{}
func (b *BufferObserverAdapter) SizeChanged(size uint64) {
b.s.MustGetGaugeCounter(MetricBufferLengthRows.String()).(stats.GaugeCounter).Set(int64(size), b.dcName)
}
func (b *BufferObserverAdapter) LengthChanged(l uint64) {
b.s.MustGetGaugeCounter(MetricBufferLengthRows.String()).(stats.GaugeCounter).Set(int64(l), b.dcName)
}
func (b *BufferObserverAdapter) Write(n int) {
b.s.MustGetSequentialCounter(MetricBufferTotalWriteLengthRows.String()).IncBy(int64(n), b.dcName)
}
func (b *BufferObserverAdapter) Read(n int) {
b.s.MustGetSequentialCounter(MetricBufferTotalReadLengthRows.String()).IncBy(int64(n), b.dcName)
}
func NewBufferObserverAdapter(s *stats.Stats, dcName string) *BufferObserverAdapter {
s.MustGetGaugeCounter(MetricBufferLengthRows.String()).Set(0, dcName)
s.MustGetGaugeCounter(MetricBufferSizeBytes.String()).Set(0, dcName)
return &BufferObserverAdapter{
s: s,
dcName: dcName,
}
}
func NewStats() *stats.Stats {
s := stats.New()
s.RegisterGaugeCounter(
MetricBufferSizeBytes.String(),
"buffer size in bytes",
)
s.RegisterGaugeCounter(
MetricBufferLengthRows.String(),
"buffer size in rows",
)
s.RegisterSequentialCounter(
MetricBufferTotalWriteLengthRows.String(),
"total buffer writes in rows",
)
s.RegisterSequentialCounter(
MetricBufferTotalReadLengthRows.String(),
"total buffer reads in rows",
)
return s
}