mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package sinks
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
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 {
|
|
switch v.(type) {
|
|
case float64:
|
|
if !math.IsNaN(v.(float64)) {
|
|
fieldstr = append(fieldstr, fmt.Sprintf("%s=%v", k, v.(float64)))
|
|
}
|
|
case string:
|
|
fieldstr = append(fieldstr, fmt.Sprintf("%s=%q", k, v.(string)))
|
|
}
|
|
}
|
|
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
|
|
}
|