forked from martensson/nixy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.go
More file actions
35 lines (27 loc) · 692 Bytes
/
Copy pathstats.go
File metadata and controls
35 lines (27 loc) · 692 Bytes
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
package main
import (
"os"
"time"
"github.com/peterbourgon/g2s"
)
func setupStatsd() (g2s.Statter, error) {
if config.Statsd.Addr == "" {
return g2s.Noop(), nil
}
if config.Statsd.Namespace == "" {
hostname, _ := os.Hostname()
config.Statsd.Namespace = "nixy." + hostname
}
if config.Statsd.SampleRate < 1 || config.Statsd.SampleRate > 100 {
config.Statsd.SampleRate = 100
}
return g2s.Dial("udp", config.Statsd.Addr)
}
func statsCount(metric string, n int) {
ns := config.Statsd.Namespace
statsd.Counter(1.0, ns+"."+metric, n)
}
func statsTiming(metric string, elapsed time.Duration) {
ns := config.Statsd.Namespace
statsd.Timing(1.0, ns+"."+metric, elapsed)
}