-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
99 lines (79 loc) · 1.7 KB
/
example_test.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package statsd_test
import (
"fmt"
"time"
"github.com/cv-library/statsd"
)
func ExampleTiming() {
for i:=0; i<10; i++ {
timer := statsd.Timer()
// Do work
took := timer.Send("work.duration")
timer.SendWithOptions(
&statsd.Options{ Rate: 0.25 },
"work.duration.sampled",
)
fmt.Printf("Took %f seconds\n", took.Seconds())
}
}
func ExampleTimer() {
// This is slightly more efficient than the Timing example
// since we avoid creating a new Timing every time
timer := statsd.Timer()
for i:=0; i<10; i++ {
timer.Reset()
// Do work
took := timer.Send("work.duration")
timer.SendWithOptions(
&statsd.Options{ Rate: 0.25 },
"work.duration.sampled",
)
fmt.Printf("Took %f seconds\n", took.Seconds())
}
}
func ExampleTime() {
for i:=0; i<10; i++ {
start := time.Now()
// Do work
statsd.Time("work.duration", time.Since(start))
}
}
func ExampleTimeWithOptions() {
for i:=0; i<10; i++ {
start := time.Now()
// Do work
if i % 2 == 0 {
continue
}
// We use AlwaysSend: true here because we're doing the sampling
// ourselves; we want every packet to reach the server
statsd.TimeWithOptions(
&statsd.Options{ Rate: 0.5, AlwaysSend: true },
"work.duration.sampled",
time.Since(start),
)
}
}
func ExampleInc() {
// Increment a counter
statsd.Inc("stats.success")
}
func ExampleIncWithOptions() {
// Increment a counter every other time
statsd.IncWithOptions(
&statsd.Options{ Rate: 0.5 },
"stats.success",
)
}
func ExampleGauge() {
// Set page size to 10
statsd.Gauge("page.size", 10)
}
func ExampleGaugeWithOptions() {
// Set page size to 10 every other time
statsd.GaugeWithOptions(
&statsd.Options{ Rate: 0.5 },
"page.size",
10,
)
}