-
Notifications
You must be signed in to change notification settings - Fork 5
/
telegraf.go
66 lines (55 loc) · 1.58 KB
/
telegraf.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
package metrics
import (
"strings"
"time"
statsd "github.com/alexcesaro/statsd"
)
type telegrafStatter struct {
client *statsd.Client
Statter
}
// telegrafStatter is wrapper of telegraf, implementing the statter
func newTelegrafStatter(opts ...statsd.Option) (Statter, error) {
c, err := statsd.New(opts...)
if err != nil {
return nil, err
}
statter := &telegrafStatter{
client: c,
}
return statter, nil
}
func (t *telegrafStatter) Count(bucket string, value int64, tags []string, rate float64) (err error) {
s := bucket + "," + strings.Join(tags, ",")
t.client.Count(s, value)
return nil
}
func (t *telegrafStatter) Incr(bucket string, tags []string, rate float64) error {
s := bucket + "," + strings.Join(tags, ",")
t.client.Increment(s)
return nil
}
func (t *telegrafStatter) Decr(bucket string, tags []string, rate float64) error {
s := bucket + "," + strings.Join(tags, ",")
t.client.Count(s, -1)
return nil
}
func (t *telegrafStatter) Gauge(bucket string, value float64, tags []string, rate float64) error {
s := bucket + "," + strings.Join(tags, ",")
t.client.Gauge(s, value)
return nil
}
func (t *telegrafStatter) Timing(bucket string, value time.Duration, tags []string, rate float64) error {
s := bucket + "," + strings.Join(tags, ",")
t.client.Timing(s, int(value/time.Millisecond))
return nil
}
func (t *telegrafStatter) Histogram(bucket string, value float64, tags []string, rate float64) error {
s := bucket + "," + strings.Join(tags, ",")
t.client.Histogram(s, value)
return nil
}
func (t *telegrafStatter) Close() error {
t.client.Close()
return nil
}