2015-05-22 23:45:14 +00:00
|
|
|
package telegraf
|
2015-04-06 16:32:10 +00:00
|
|
|
|
2015-04-07 00:24:24 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
2015-05-27 05:14:42 +00:00
|
|
|
"time"
|
2015-04-07 00:24:24 +00:00
|
|
|
|
|
|
|
"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)
|
|
|
|
|
2015-05-27 05:14:42 +00:00
|
|
|
fmt.Printf("> [%s] %s value=%v\n", strings.Join(tg, " "), name, val)
|
2015-04-07 00:24:24 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2015-05-27 05:14:42 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|