Add new line protocol parser and serializer, influxdb output (#3924)

This commit is contained in:
Daniel Nelson
2018-03-27 17:30:51 -07:00
committed by GitHub
parent 720c27559c
commit 222a68d72e
70 changed files with 26827 additions and 6533 deletions

View File

@@ -2,6 +2,7 @@ package nagios
import (
"regexp"
"strconv"
"strings"
"time"
@@ -72,23 +73,41 @@ func (p *NagiosParser) Parse(buf []byte) ([]telegraf.Metric, error) {
fieldName := string(perf[0][1])
tags := make(map[string]string)
if perf[0][3] != nil {
tags["unit"] = string(perf[0][3])
str := string(perf[0][3])
if str != "" {
tags["unit"] = str
}
}
fields := make(map[string]interface{})
fields["value"] = perf[0][2]
f, err := strconv.ParseFloat(string(perf[0][2]), 64)
if err == nil {
fields["value"] = f
}
// TODO should we set empty field
// if metric if there is no data ?
if perf[0][4] != nil {
fields["warning"] = perf[0][4]
f, err := strconv.ParseFloat(string(perf[0][4]), 64)
if err == nil {
fields["warning"] = f
}
}
if perf[0][5] != nil {
fields["critical"] = perf[0][5]
f, err := strconv.ParseFloat(string(perf[0][5]), 64)
if err == nil {
fields["critical"] = f
}
}
if perf[0][6] != nil {
fields["min"] = perf[0][6]
f, err := strconv.ParseFloat(string(perf[0][6]), 64)
if err == nil {
fields["min"] = f
}
}
if perf[0][7] != nil {
fields["max"] = perf[0][7]
f, err := strconv.ParseFloat(string(perf[0][7]), 64)
if err == nil {
fields["max"] = f
}
}
// Create metric
metric, err := metric.New(fieldName, tags, fields, time.Now().UTC())