Implement telegraf's own full metric type

main reasons behind this:
- make adding/removing tags cheap
- make adding/removing fields cheap
- make parsing cheaper
- make parse -> decorate -> write out bytes metric flow much faster

Refactor serializer to use byte buffer
This commit is contained in:
Cameron Sparr
2016-11-22 12:51:57 +00:00
parent 332f678afb
commit db7a4b24b6
40 changed files with 1376 additions and 398 deletions

View File

@@ -1,7 +1,6 @@
package amqp
import (
"bytes"
"fmt"
"log"
"strings"
@@ -178,7 +177,7 @@ func (q *AMQP) Write(metrics []telegraf.Metric) error {
if len(metrics) == 0 {
return nil
}
var outbuf = make(map[string][][]byte)
outbuf := make(map[string][]byte)
for _, metric := range metrics {
var key string
@@ -188,14 +187,12 @@ func (q *AMQP) Write(metrics []telegraf.Metric) error {
}
}
values, err := q.serializer.Serialize(metric)
buf, err := q.serializer.Serialize(metric)
if err != nil {
return err
}
for _, value := range values {
outbuf[key] = append(outbuf[key], []byte(value))
}
outbuf[key] = append(outbuf[key], buf...)
}
for key, buf := range outbuf {
@@ -207,7 +204,7 @@ func (q *AMQP) Write(metrics []telegraf.Metric) error {
amqp.Publishing{
Headers: q.headers,
ContentType: "text/plain",
Body: bytes.Join(buf, []byte("\n")),
Body: buf,
})
if err != nil {
return fmt.Errorf("FAILED to send amqp message: %s", err)