-
Notifications
You must be signed in to change notification settings - Fork 2
/
csv.go
60 lines (54 loc) · 1.3 KB
/
csv.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
package olbermann
import (
"bufio"
"fmt"
"time"
)
// CsvStyler is a Styler that produces output in csv format.
type CsvStyler struct {
Period time.Duration // How often to print
Writer *bufio.Writer // A writer to print to
}
func (s *CsvStyler) period() time.Duration {
return s.Period
}
func (s *CsvStyler) linesBetweenHeaders() int {
return 0
}
func (s *CsvStyler) printHeader(mst *metricSetType) {
s.Writer.WriteString("time")
for i := range mst.metrics {
mt := mst.metrics[i]
s.Writer.WriteString(",")
for j := range mt.reports {
rt := mt.reports[j]
if j > 0 {
s.Writer.WriteString(",")
}
s.Writer.WriteString("\"")
s.Writer.WriteString(mt.name)
s.Writer.WriteString(" ")
s.Writer.WriteString(rt.name())
s.Writer.WriteString("\"")
}
}
s.Writer.WriteString("\n")
}
func (s *CsvStyler) printValues(curTime time.Time, mst *metricSetType, msv *metricSetValue) {
s.Writer.WriteString("\"")
s.Writer.WriteString(curTime.String())
s.Writer.WriteString("\"")
for i := range msv.metrics {
mv := msv.metrics[i]
s.Writer.WriteString(",")
for j := range mv.reports {
rv := mv.reports[j]
if j > 0 {
s.Writer.WriteString(",")
}
s.Writer.WriteString(fmt.Sprintf("%f", rv.value))
}
}
s.Writer.WriteString("\n")
s.Writer.Flush()
}