-
Notifications
You must be signed in to change notification settings - Fork 9
/
stdout_output.go
72 lines (63 loc) · 1.63 KB
/
stdout_output.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
67
68
69
70
71
72
package shh
import (
"fmt"
"time"
)
type StdOutL2MetRaw struct {
measurements <-chan Measurement
prefix string
source string
}
func NewStdOutL2MetRaw(measurements <-chan Measurement, config Config) *StdOutL2MetRaw {
return &StdOutL2MetRaw{measurements: measurements, prefix: config.Prefix, source: config.Source}
}
func (out *StdOutL2MetRaw) Start() {
go out.Output()
}
func (out *StdOutL2MetRaw) Output() {
for mm := range out.measurements {
msg := fmt.Sprintf("when=%s sample#%s=%s", mm.Time().Format(time.RFC3339), mm.Name(out.prefix), mm.StrValue())
if out.source != "" {
Logger.Println(fmt.Sprintf("%s source=%s", msg, out.source))
continue
}
Logger.Println(msg)
}
}
type StdOutL2MetDer struct {
incoming <-chan Measurement
outgoing chan<- Measurement
last map[string]CounterMeasurement
raw *StdOutL2MetRaw
prefix string
}
func NewStdOutL2MetDer(measurements <-chan Measurement, config Config) *StdOutL2MetDer {
plex := make(chan Measurement)
return &StdOutL2MetDer{
incoming: measurements,
outgoing: plex,
last: make(map[string]CounterMeasurement),
raw: NewStdOutL2MetRaw(plex, config),
prefix: config.Prefix,
}
}
func (out *StdOutL2MetDer) Start() {
go out.Output()
go out.raw.Output()
}
func (out *StdOutL2MetDer) Output() {
for mm := range out.incoming {
switch mm.Type() {
case CounterType:
key := mm.Name(out.prefix)
last, found := out.last[key]
cm := mm.(CounterMeasurement)
out.last[key] = cm
if found {
out.outgoing <- CounterMeasurement{cm.time, cm.poller, cm.what, cm.Difference(last), Empty}
}
default:
out.outgoing <- mm
}
}
}