forked from heroku/lumbermill
/
destination.go
49 lines (40 loc) · 1.01 KB
/
destination.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
package main
import (
"time"
metrics "github.com/heroku/lumbermill/Godeps/_workspace/src/github.com/rcrowley/go-metrics"
)
// A channel of points and related sampling
type destination struct {
Name string
points chan point
depthGauge metrics.Gauge
}
func newDestination(name string, chanCap int) *destination {
destination := &destination{Name: name}
destination.points = make(chan point, chanCap)
destination.depthGauge = metrics.GetOrRegisterGauge(
"lumbermill.points.pending."+name,
metrics.DefaultRegistry,
)
go destination.Sample(10 * time.Second)
return destination
}
// Update depth guages every so often
func (d *destination) Sample(every time.Duration) {
for {
time.Sleep(every)
d.depthGauge.Update(int64(len(d.points)))
}
}
// Post the point, or increment a counter if channel is full
func (d *destination) PostPoint(point point) {
select {
case d.points <- point:
default:
droppedErrorCounter.Inc(1)
}
}
func (d *destination) Close() error {
close(d.points)
return nil
}