2021-03-26 17:03:46 +01:00
|
|
|
package sinks
|
|
|
|
|
|
|
|
import (
|
2021-03-26 17:08:00 +01:00
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2021-03-26 17:03:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type StdoutSink struct {
|
|
|
|
Sink
|
|
|
|
}
|
|
|
|
|
2021-05-18 15:16:10 +02:00
|
|
|
func (s *StdoutSink) Init(config SinkConfig) error {
|
2021-03-26 17:03:46 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StdoutSink) Write(measurement string, tags map[string]string, fields map[string]interface{}, t time.Time) error {
|
2021-03-26 17:08:00 +01:00
|
|
|
var tagsstr []string
|
|
|
|
var fieldstr []string
|
|
|
|
for k, v := range tags {
|
|
|
|
tagsstr = append(tagsstr, fmt.Sprintf("%s=%s", k, v))
|
|
|
|
}
|
|
|
|
for k, v := range fields {
|
2021-05-18 15:16:10 +02:00
|
|
|
switch v.(type) {
|
|
|
|
case float64:
|
|
|
|
if !math.IsNaN(v.(float64)) {
|
|
|
|
fieldstr = append(fieldstr, fmt.Sprintf("%s=%v", k, v.(float64)))
|
|
|
|
}
|
2021-05-12 17:46:16 +02:00
|
|
|
case string:
|
2021-05-18 15:16:10 +02:00
|
|
|
fieldstr = append(fieldstr, fmt.Sprintf("%s=%q", k, v.(string)))
|
2021-03-26 17:08:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(tagsstr) > 0 {
|
|
|
|
fmt.Printf("%s,%s %s %d\n", measurement, strings.Join(tagsstr, ","), strings.Join(fieldstr, ","), t.Unix())
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s %s %d\n", measurement, strings.Join(fieldstr, ","), t.Unix())
|
|
|
|
}
|
|
|
|
return nil
|
2021-03-26 17:03:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StdoutSink) Close() {
|
2021-03-26 17:08:00 +01:00
|
|
|
return
|
2021-03-26 17:03:46 +01:00
|
|
|
}
|