File: init.go

package info (click to toggle)
golang-github-raintank-met 0.0~git20190828.80f9c6e-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download | duplicates (3)
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
// a metrics class that uses dogstatsd on the backend

// note that on creation, we automatically send a default value so that:
// * influxdb doesn't complain when queried for series that don't exist yet, which breaks graphs in grafana
// * the series show up in your monitoring tool of choice, so you can easily do alerting rules, build dashes etc
// without having to wait for data. some series would otherwise only be created when things go badly wrong etc.
// note that for gauges and timers this can create inaccuracies because the true values are hard to predict,
// but it's worth the trade-off.
// (for count 0 is harmless and accurate)

package dogstatsd

import "github.com/DataDog/datadog-go/statsd"

type Backend struct {
	client *statsd.Client
}

// note: library does not auto-add ending dot to prefix, specify it if you want it
func New(addr, prefix string, tags []string) (Backend, error) {
	client, err := statsd.New(addr)
	if err == nil {
		client.Namespace = prefix
		client.Tags = tags
	}
	return Backend{client}, err
}