2015-04-06 16:32:10 +00:00
|
|
|
package tivan
|
|
|
|
|
2015-04-07 00:24:24 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/influxdb/influxdb/client"
|
|
|
|
)
|
2015-04-06 16:32:10 +00:00
|
|
|
|
|
|
|
type BatchPoints struct {
|
|
|
|
client.BatchPoints
|
2015-04-07 00:24:24 +00:00
|
|
|
|
|
|
|
Debug bool
|
2015-05-18 19:15:15 +00:00
|
|
|
|
|
|
|
Prefix string
|
2015-05-20 05:19:32 +00:00
|
|
|
|
|
|
|
Config *ConfiguredPlugin
|
2015-04-06 16:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bp *BatchPoints) Add(name string, val interface{}, tags map[string]string) {
|
2015-05-18 19:15:15 +00:00
|
|
|
name = bp.Prefix + name
|
|
|
|
|
2015-05-20 05:19:32 +00:00
|
|
|
if bp.Config != nil {
|
|
|
|
if !bp.Config.ShouldPass(name) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 00:24:24 +00:00
|
|
|
if bp.Debug {
|
|
|
|
var tg []string
|
|
|
|
|
|
|
|
for k, v := range tags {
|
|
|
|
tg = append(tg, fmt.Sprintf("%s=\"%s\"", k, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Strings(tg)
|
|
|
|
|
|
|
|
fmt.Printf("> [%s] %s=%v\n", strings.Join(tg, " "), name, val)
|
|
|
|
}
|
|
|
|
|
2015-04-06 16:32:10 +00:00
|
|
|
bp.Points = append(bp.Points, client.Point{
|
|
|
|
Name: name,
|
|
|
|
Tags: tags,
|
|
|
|
Fields: map[string]interface{}{
|
|
|
|
"value": val,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|