This repository has been archived by the owner on Jul 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
librato_test.go
65 lines (59 loc) · 2.53 KB
/
librato_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
package librato
import (
"fmt"
"os"
"testing"
"time"
)
func newClient() *Librato {
err := make(chan error, 10)
config := Config{
Email: os.Getenv("LIBRATO_EMAIL"),
APIKey: os.Getenv("LIBRATO_APIKEY"),
}
go func() {
for e := range err {
fmt.Println(e)
}
}()
return New(config, err)
}
// The librato API
func TestAddGauge(t *testing.T) {
l := newClient()
pubTime := time.Now().Add(time.Minute * -1)
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 1, Source: "add-gauge", MeasureTime: pubTime.Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 2, Source: "add-gauge", MeasureTime: pubTime.Add(time.Second * 5).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 4, Source: "add-gauge", MeasureTime: pubTime.Add(time.Second * 10).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 8, Source: "add-gauge", MeasureTime: pubTime.Add(time.Second * 15).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 16, Source: "add-gauge", MeasureTime: pubTime.Add(time.Second * 20).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 32, Source: "add-gauge", MeasureTime: pubTime.Add(time.Second * 25).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 64, Source: "add-gauge", MeasureTime: pubTime.Add(time.Second * 30).Unix()})
l.Shutdown()
}
func TestAddAggregate(t *testing.T) {
l := newClient()
a := Aggregate{Name: "reticulated.splines", Source: "add-aggregate"}
a.Add(12).Add(6).Add(5).Add(4).Add(5).Add(10).Add(3)
l.AddGauge(a.ToGauge())
l.Shutdown()
}
// The librato API
func TestAddCounter(t *testing.T) {
l := newClient()
pubTime := time.Now().Add(time.Minute * -1)
for i := 0; i < 10; i++ {
measureTime := pubTime.Add(time.Second * time.Duration(i*5))
l.AddCounter(Counter{Name: "reticulated.splines.counter", Value: i * i, Source: "add-counter", MeasureTime: measureTime.Unix()})
}
l.Shutdown()
}
func TestAddGuageWithTimings(t *testing.T) {
l := newClient()
pubTime := time.Now().Add(time.Minute * -1)
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 10, Source: "add-gauge-with-timing", MeasureTime: pubTime.Add(time.Second * 30).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 20, Source: "add-gauge-with-timing", MeasureTime: pubTime.Add(time.Second * 15).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 40, Source: "add-gauge-with-timing", MeasureTime: pubTime.Add(time.Second * 10).Unix()})
l.AddGauge(Gauge{Name: "reticulated.splines", Value: 70, Source: "add-gauge-with-timing", MeasureTime: pubTime.Unix()})
l.Shutdown()
}