-
Notifications
You must be signed in to change notification settings - Fork 1
/
statsd.go
61 lines (54 loc) · 1.8 KB
/
statsd.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
package wbgong
import (
"log"
"time"
"github.com/alexcesaro/statsd"
)
var (
funcNewStatsdClientWrapper func(string, ...statsd.Option) (StatsdClientWrapper, error)
funcNewStatsdRuntimeCollector func(StatsdClientWrapper) StatsdRuntimeCollector
)
// StatsdClientWrapper is a wrapper around statsd client
type StatsdClientWrapper interface {
SetCallback(func(*statsd.Client))
Clone(string, ...statsd.Option) StatsdClientWrapper
Start(time.Duration)
Stop()
}
// StatsdRuntimeCollector is a runtime metrics collector for statsd
type StatsdRuntimeCollector interface {
Start()
Stop()
}
// NewStatsdClientWrapper returns new StatsdClientWrapper
func NewStatsdClientWrapper(prefix string, opts ...statsd.Option) (StatsdClientWrapper, error) {
if funcNewStatsdClientWrapper != nil {
return funcNewStatsdClientWrapper(prefix, opts...)
}
funcSym, errSym := plug.Lookup("NewStatsdClientWrapper")
if errSym != nil {
log.Fatalf("Error in lookup symbol: %s", errSym)
}
var okResolve bool
funcNewStatsdClientWrapper, okResolve = funcSym.(func(string, ...statsd.Option) (StatsdClientWrapper, error))
if !okResolve {
log.Fatal("Wrong sign on resolving func")
}
return funcNewStatsdClientWrapper(prefix, opts...)
}
// NewStatsdRuntimeCollector returns new StatsdRuntimeCollector
func NewStatsdRuntimeCollector(client StatsdClientWrapper) StatsdRuntimeCollector {
if funcNewStatsdRuntimeCollector != nil {
return funcNewStatsdRuntimeCollector(client)
}
funcSym, errSym := plug.Lookup("NewStatsdRuntimeCollector")
if errSym != nil {
log.Fatalf("Error in lookup symbol: %s", errSym)
}
var okResolve bool
funcNewStatsdRuntimeCollector, okResolve = funcSym.(func(StatsdClientWrapper) StatsdRuntimeCollector)
if !okResolve {
log.Fatal("Wrong sign on resolving func")
}
return funcNewStatsdRuntimeCollector(client)
}