/
metrics.go
59 lines (54 loc) · 1.23 KB
/
metrics.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
package main
import (
"os"
"time"
"github.com/InjectiveLabs/metrics"
cli "github.com/jawher/mow.cli"
"github.com/xlab/closer"
log "github.com/xlab/suplog"
)
func initMetrics(c *cli.Cmd) {
var (
statsdAgent *string
statsdPrefix *string
statsdAddr *string
statsdStuckDur *string
statsdMocking *string
statsdDisabled *string
)
initStatsdOptions(
c,
&statsdAgent,
&statsdPrefix,
&statsdAddr,
&statsdStuckDur,
&statsdMocking,
&statsdDisabled,
)
if toBool(*statsdDisabled) {
// initializes statsd client with a mock one with no-op enabled
metrics.Disable()
} else {
go func() {
for {
hostname, _ := os.Hostname()
err := metrics.Init(*statsdAddr, checkStatsdPrefix(*statsdPrefix), &metrics.StatterConfig{
Agent: *statsdAgent,
EnvName: *envName,
HostName: hostname,
StuckFunctionTimeout: duration(*statsdStuckDur, 30*time.Minute),
MockingEnabled: toBool(*statsdMocking) || *envName == "local",
})
if err != nil {
log.WithError(err).Warningln("metrics init failed, will retry in 1 min")
time.Sleep(time.Minute)
continue
}
break
}
closer.Bind(func() {
metrics.Close()
})
}()
}
}