forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
57 lines (46 loc) · 867 Bytes
/
provider.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
package metrics
import (
"io"
"time"
"github.com/spf13/cobra"
"github.com/uber-go/tally"
)
var (
scope = tally.NoopScope
closer io.Closer
port int
startExposure []func()
)
func RegisterRootScope(s tally.ScopeOptions, exposedPort int) {
scope, closer = tally.NewRootScope(s, 1*time.Second)
port = exposedPort
}
func RegisterOnStartExposure(runFunc func()) {
startExposure = append(startExposure, runFunc)
}
func Init() {
if len(startExposure) > 0 {
cobra.OnInitialize(func() {
for _, f := range startExposure {
f()
}
})
}
}
func Close() {
port = 0
if closer != nil {
closer.Close()
}
}
func GetExposedPort() int {
return port
}
func GetMetrics() tally.Scope {
return scope
}
func GetMetricsForService(serviceName string) tally.Scope {
return scope.Tagged(map[string]string{
"service": serviceName,
})
}