GoでDogStatsDにCustom Metricsを送信する

Table of Contents

References

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
var Dogstatsd *statsd.Client

func InitializeDogstatsd(host string, port string, env string, options ...statsd.Option) {
	if host == "" && env == "development" {
		host = "127.0.0.1"
	}

	tags := []string{
		"env:" + env,
	}
	options = append(options, statsd.WithTags(tags))
	addr := host + ":" + port
	statsd, err := statsd.New(addr, options...)
	if err != nil {
		log.Fatalf("failed to initialize statsd client: %s", err)
	}
	Dogstatsd = statsd
}
> back to posts