Add StdoutSink for debugging purposes

This commit is contained in:
Thomas Roehl 2021-03-26 17:03:46 +01:00
parent f822f00cdc
commit 913c3719a9
3 changed files with 46 additions and 1 deletions

View File

@ -5,7 +5,7 @@
"host": "localhost", "host": "localhost",
"port": "8080", "port": "8080",
"database": "testdb", "database": "testdb",
"type": "influxdb" "type": "stdout"
}, },
"interval" : 3, "interval" : 3,
"duration" : 1, "duration" : 1,

View File

@ -26,6 +26,7 @@ var Collectors = map[string]collectors.MetricGetter{
var Sinks = map[string]sinks.SinkFuncs{ var Sinks = map[string]sinks.SinkFuncs{
"influxdb": &sinks.InfluxSink{}, "influxdb": &sinks.InfluxSink{},
"stdout": &sinks.StdoutSink{},
} }
// Structure of the configuration file // Structure of the configuration file

44
sinks/stdoutSink.go Normal file
View File

@ -0,0 +1,44 @@
package sinks
import (
"fmt"
"time"
"strings"
"math"
)
type StdoutSink struct {
Sink
}
func (s *StdoutSink) Init(host string, port string, user string, password string, database string) error {
s.host = host
s.port = port
s.user = user
s.password = password
s.database = database
return nil
}
func (s *StdoutSink) Write(measurement string, tags map[string]string, fields map[string]interface{}, t time.Time) error {
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 {
if !math.IsNaN(v.(float64)) {
fieldstr = append(fieldstr, fmt.Sprintf("%s=%v", k, v.(float64)))
}
}
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
}
func (s *StdoutSink) Close() {
return
}