File: helper.go

package info (click to toggle)
golang-github-raintank-met 0.0~git20161103.0.05a94bb-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 172 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 670 bytes parent folder | download | duplicates (2)
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
package helper

import (
	"fmt"

	"github.com/raintank/met"
	"github.com/raintank/met/dogstatsd"
	"github.com/raintank/met/statsd"
)

func New(enabled bool, addr, t, service, instance string) (met.Backend, error) {
	if t != "standard" && t != "datadog" {
		panic(fmt.Sprintf("unrecognized statsd type: '%s'", t))
	}
	if !enabled {
		// we could implement a true "null-backend"
		// but since statsd supports disabled mode, this is easier
		return statsd.New(enabled, addr, "")
	}
	if t == "standard" {
		return statsd.New(enabled, addr, fmt.Sprintf("%s.%s.", service, instance))
	} else {
		return dogstatsd.New(addr, service+".", []string{"instance:" + instance})
	}
}