-
Notifications
You must be signed in to change notification settings - Fork 3
/
backend_librato.go
47 lines (36 loc) · 922 Bytes
/
backend_librato.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
package poller
import (
"fmt"
"github.com/rcrowley/go-librato"
"time"
)
type libratoBackend struct {
metrics librato.Metrics
prefix string
}
func NewLibratoBackend(user, token, source, prefix string) (Backend, error) {
if user == "" {
return nil, fmt.Errorf("Librato user cannot be empty")
}
if token == "" {
return nil, fmt.Errorf("Librato token cannot be empty")
}
if source == "" {
source = "poller"
}
if prefix == "" {
prefix = "checks."
}
metrics := librato.NewSimpleMetrics(user, token, source)
return &libratoBackend{metrics: metrics, prefix: prefix}, nil
}
func (l *libratoBackend) Log(e *Event) {
d := l.metrics.GetGauge(l.prefix + e.Check.Key + ".duration")
d <- int64(e.Duration.Nanoseconds() / int64(time.Millisecond))
c := l.metrics.GetGauge(l.prefix + e.Check.Key + ".up")
c <- btou(e.IsUp())
}
func (l *libratoBackend) Close() {
l.metrics.Close()
l.metrics.Wait()
}