Value parser, for parsing a single value into a metric

closes #849
This commit is contained in:
Cameron Sparr
2016-03-17 18:01:01 -06:00
parent 26e0a4bbde
commit 5c1b635229
5 changed files with 375 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/influxdata/telegraf/plugins/parsers/graphite"
"github.com/influxdata/telegraf/plugins/parsers/influx"
"github.com/influxdata/telegraf/plugins/parsers/json"
"github.com/influxdata/telegraf/plugins/parsers/value"
)
// ParserInput is an interface for input plugins that are able to parse
@@ -38,7 +39,7 @@ type Parser interface {
// Config is a struct that covers the data types needed for all parser types,
// and can be used to instantiate _any_ of the parsers.
type Config struct {
// Dataformat can be one of: json, influx, graphite
// Dataformat can be one of: json, influx, graphite, value
DataFormat string
// Separator only applied to Graphite data.
@@ -48,9 +49,12 @@ type Config struct {
// TagKeys only apply to JSON data
TagKeys []string
// MetricName only applies to JSON data. This will be the name of the measurement.
// MetricName applies to JSON & value. This will be the name of the measurement.
MetricName string
// DataType only applies to value, this will be the type to parse value to
DataType string
// DefaultTags are the default tags that will be added to all parsed metrics.
DefaultTags map[string]string
}
@@ -63,6 +67,9 @@ func NewParser(config *Config) (Parser, error) {
case "json":
parser, err = NewJSONParser(config.MetricName,
config.TagKeys, config.DefaultTags)
case "value":
parser, err = NewValueParser(config.MetricName,
config.DataType, config.DefaultTags)
case "influx":
parser, err = NewInfluxParser()
case "graphite":
@@ -98,3 +105,15 @@ func NewGraphiteParser(
) (Parser, error) {
return graphite.NewGraphiteParser(separator, templates, defaultTags)
}
func NewValueParser(
metricName string,
dataType string,
defaultTags map[string]string,
) (Parser, error) {
return &value.ValueParser{
MetricName: metricName,
DataType: dataType,
DefaultTags: defaultTags,
}, nil
}