-
Notifications
You must be signed in to change notification settings - Fork 6
/
reports.go
82 lines (66 loc) · 1.87 KB
/
reports.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
79
80
81
82
package metrics
import (
"strconv"
"time"
"golang.org/x/exp/constraints"
)
func CustomReport(reportFn func(s Statter, tagSpec []string), tags ...Tags) {
clientMux.RLock()
defer clientMux.RUnlock()
if client == nil {
return
}
reportFn(client, JoinTags(tags...))
}
func SlowSubscriberEventsDropped(amount int, tags ...Tags) {
CustomReport(func(s Statter, tagSpec []string) {
s.Count("pubsub.slow_subscriber.events_dropped", int64(amount), tagSpec, 1)
})
}
func SpotTradesBatchSubmitted(size int, tags ...Tags) {
CustomReport(func(s Statter, tagSpec []string) {
s.Count("events.spot_trades_batch.size", int64(size), tagSpec, 1)
})
}
func DerivativeTradesBatchSubmitted(size int, tags ...Tags) {
CustomReport(func(s Statter, tagSpec []string) {
s.Count("events.derivative_trades_batch.size", int64(size), tagSpec, 1)
})
}
func IndexPriceUpdatesBatchSubmitted(size int, tags ...Tags) {
CustomReport(func(s Statter, tagSpec []string) {
s.Count("events.set_price_batch.size", int64(size), tagSpec, 1)
})
}
func Counter[T constraints.Integer](metric string, value T, tags ...Tags) {
CustomReport(func(s Statter, tagSpec []string) {
s.Count(metric, int64(value), tagSpec, 1)
}, tags...)
}
func CounterPositive[T constraints.Integer](metric string, value T, tags ...Tags) {
if value > 0 {
Counter(metric, value, tags...)
}
}
func Incr(metric string, tags ...Tags) {
Counter(metric, 1, tags...)
}
func Timer(metric string, value time.Duration, tags ...Tags) {
CustomReport(func(s Statter, tagSpec []string) {
s.Timing(metric, value, tagSpec, 1)
}, tags...)
}
func Gauge(metric string, value float64, tags ...Tags) {
CustomReport(func(s Statter, tagSpec []string) {
s.Gauge(metric, value, tagSpec, 1)
}, tags...)
}
func BoolTag(b bool) string {
if b {
return "true"
}
return "false"
}
func IntTag[T constraints.Integer](i T) string {
return strconv.Itoa(int(i))
}