This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
init.go
52 lines (45 loc) · 1.69 KB
/
init.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
package config
import (
"flag"
"strings"
"time"
"github.com/grafana/globalconf"
"github.com/grafana/metrictank/stats"
log "github.com/sirupsen/logrus"
)
var enabled bool
var prefix string
var addr string
var interval int
var bufferSize int
var timeout time.Duration
func ConfigSetup() {
inStats := flag.NewFlagSet("stats", flag.ExitOnError)
inStats.BoolVar(&enabled, "enabled", true, "enable sending graphite messages for instrumentation")
inStats.StringVar(&prefix, "prefix", "metrictank.stats.default.$instance", "stats prefix (will add trailing dot automatically if needed)")
inStats.StringVar(&addr, "addr", "localhost:2003", "graphite address")
inStats.IntVar(&interval, "interval", 1, "interval at which to send statistics")
inStats.DurationVar(&timeout, "timeout", time.Second*10, "timeout after which a write is considered not successful")
inStats.IntVar(&bufferSize, "buffer-size", 20000, "how many messages (holding all measurements from one interval. rule of thumb: a message is ~25kB) to buffer up in case graphite endpoint is unavailable. With the default of 20k you will use max about 500MB and bridge 5 hours of downtime when needed")
globalconf.Register("stats", inStats, flag.ExitOnError)
}
func ConfigProcess(instance string) {
if !enabled {
return
}
// TODO validate tcp addr
prefix = strings.Replace(prefix, "$instance", instance, -1)
}
func Start() {
if enabled {
stats.NewMemoryReporter()
_, err := stats.NewProcessReporter()
if err != nil {
log.Fatalf("stats: could not initialize process reporter: %v", err)
}
stats.NewGraphite(prefix, addr, interval, bufferSize, timeout)
} else {
stats.NewDevnull()
log.Warn("running metrictank without instrumentation.")
}
}