Add 'AddValuesWithTime' function to accumulator

This commit is contained in:
Evan Phoenix
2015-05-26 22:14:42 -07:00
parent dcd7861c1a
commit 2667183bfb
4 changed files with 100 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"sort"
"strings"
"time"
"github.com/influxdb/influxdb/client"
)
@@ -36,7 +37,7 @@ func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string)
sort.Strings(tg)
fmt.Printf("> [%s] %s=%v\n", strings.Join(tg, " "), name, val)
fmt.Printf("> [%s] %s value=%v\n", strings.Join(tg, " "), name, val)
}
bp.Points = append(bp.Points, client.Point{
@@ -47,3 +48,44 @@ func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string)
},
})
}
func (bp *BatchPoints) AddValuesWithTime(
name string,
values map[string]interface{},
tags map[string]string,
timestamp time.Time,
) {
name = bp.Prefix + name
if bp.Config != nil {
if !bp.Config.ShouldPass(name) {
return
}
}
if bp.Debug {
var tg []string
for k, v := range tags {
tg = append(tg, fmt.Sprintf("%s=\"%s\"", k, v))
}
var vals []string
for k, v := range values {
vals = append(vals, fmt.Sprintf("%s=%v", k, v))
}
sort.Strings(tg)
sort.Strings(vals)
fmt.Printf("> [%s] %s %s\n", strings.Join(tg, " "), name, strings.Join(vals, " "))
}
bp.Points = append(bp.Points, client.Point{
Name: name,
Tags: tags,
Fields: values,
Time: timestamp,
})
}