forked from influxdata/influxdb-comparisons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
telemetry.go
58 lines (48 loc) · 1023 Bytes
/
telemetry.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
package report
import (
"log"
"os"
)
// TelemetryRunAsync runs a collection loop with many defaults already set. It will
// abort the program if an error occurs. Assumes points are owned by the
// GlobalPointPool.
func TelemetryRunAsync(c *Collector, batchSize uint64, writeToStderr bool, skipN uint64) (src chan *Point, done chan struct{}) {
src = make(chan *Point, 100)
done = make(chan struct{})
send := func() {
c.PrepBatch()
if writeToStderr {
_, err := os.Stderr.Write(c.buf.Bytes())
if err != nil {
log.Fatalf("collector error (stderr): %v", err.Error())
}
}
err := c.SendBatch()
if err != nil {
log.Fatalf("collector error (http): %v", err.Error())
}
for _, p := range c.Points {
PutPointIntoGlobalPool(p)
}
}
go func() {
var i uint64
for p := range src {
i++
if i <= skipN {
continue
}
c.Put(p)
if i%batchSize == 0 {
send()
c.Reset()
}
}
if len(c.Points) > 0 {
send()
c.Reset()
}
done <- struct{}{}
}()
return
}