/
init.go
33 lines (25 loc) · 752 Bytes
/
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
package metrics
import (
"fmt"
"strings"
log "github.com/sirupsen/logrus"
"gopkg.in/alexcesaro/statsd.v2"
)
// NewStatsd возвращает новый настроенный клиент statsd
func NewStatsd(host string, port int, protocol string, prefix string, enable bool) (*statsd.Client, error) {
protocol = strings.ToLower(protocol)
muted := !enable
log.Infof(
`Create statsd client to %v:%v via %v with prefix "%v", muted is %v.`,
host, port, protocol, prefix, muted)
client, err := statsd.New(
statsd.Address(fmt.Sprintf("%v:%v", host, port)),
statsd.Prefix(prefix),
statsd.Network(protocol),
statsd.Mute(muted))
log.Info("Statsd client was created.")
if err != nil {
return nil, err
}
return client, nil
}