-
Notifications
You must be signed in to change notification settings - Fork 426
/
statsd.go
35 lines (29 loc) · 1.07 KB
/
statsd.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.
package internal
import (
"time"
"github.com/DataDog/datadog-go/v5/statsd"
)
const DefaultDogstatsdAddr = "localhost:8125"
type StatsdClient interface {
Incr(name string, tags []string, rate float64) error
Count(name string, value int64, tags []string, rate float64) error
Gauge(name string, value float64, tags []string, rate float64) error
Timing(name string, value time.Duration, tags []string, rate float64) error
Flush() error
Close() error
}
// NewStatsdClient returns a new statsd client with the provided address and globaltags
func NewStatsdClient(addr string, globalTags []string) (StatsdClient, error) {
if addr == "" {
addr = DefaultDogstatsdAddr
}
client, err := statsd.New(addr, statsd.WithMaxMessagesPerPayload(40), statsd.WithTags(globalTags))
if err != nil {
return &statsd.NoOpClient{}, err
}
return client, nil
}