-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathxstats_example_test.go
More file actions
80 lines (61 loc) · 2 KB
/
xstats_example_test.go
File metadata and controls
80 lines (61 loc) · 2 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package xstats_test
import (
"log"
"net"
"time"
"github.com/rs/xstats"
"github.com/rs/xstats/dogstatsd"
)
func ExampleNew() {
// Defines interval between flushes to statsd server
flushInterval := 5 * time.Second
// Connection to the statsd server
statsdWriter, err := net.Dial("udp", "127.0.0.1:8126")
if err != nil {
log.Fatal(err)
}
// Create the stats client
s := xstats.New(dogstatsd.New(statsdWriter, flushInterval))
// Global tags sent with all metrics (only with supported clients like datadog's)
s.AddTags("role:my-service", "dc:sv6")
// Send some observations
s.Count("requests", 1, "tag")
s.Timing("something", 5*time.Millisecond, "tag")
}
func ExampleNewScoping() {
// Defines interval between flushes to statsd server
flushInterval := 5 * time.Second
// Connection to the statsd server
statsdWriter, err := net.Dial("udp", "127.0.0.1:8126")
if err != nil {
log.Fatal(err)
}
// Create the stats client
s := xstats.NewScoping(dogstatsd.New(statsdWriter, flushInterval), ".", "my-thing")
// Global tags sent with all metrics (only with supported clients like datadog's)
s.AddTags("role:my-service", "dc:sv6")
// Send some observations
s.Count("requests", 1, "tag")
s.Timing("something", 5*time.Millisecond, "tag")
// Scope the client
ss := xstats.Scope(s, "my-sub-thing")
ss.Histogram("latency", 50, "tag")
}
func ExampleNewMaxPacket() {
// Defines interval between flushes to statsd server
flushInterval := 5 * time.Second
// Defines the largest packet sent to the statsd server
maxPacketLen := 8192
// Connection to the statsd server
statsdWriter, err := net.Dial("udp", "127.0.0.1:8126")
if err != nil {
log.Fatal(err)
}
// Create the stats client
s := xstats.New(dogstatsd.NewMaxPacket(statsdWriter, flushInterval, maxPacketLen))
// Global tags sent with all metrics (only with supported clients like datadog's)
s.AddTags("role:my-service", "dc:sv6")
// Send some observations
s.Count("requests", 1, "tag")
s.Timing("something", 5*time.Millisecond, "tag")
}