Add support for dropwizard input format (#2846)

This commit is contained in:
atzoum
2018-01-09 01:11:36 +02:00
committed by Daniel Nelson
parent 9cfa3b292b
commit 317de40ac4
13 changed files with 1436 additions and 333 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/parsers/collectd"
"github.com/influxdata/telegraf/plugins/parsers/dropwizard"
"github.com/influxdata/telegraf/plugins/parsers/graphite"
"github.com/influxdata/telegraf/plugins/parsers/influx"
"github.com/influxdata/telegraf/plugins/parsers/json"
@@ -66,6 +67,22 @@ type Config struct {
// DefaultTags are the default tags that will be added to all parsed metrics.
DefaultTags map[string]string
// an optional json path containing the metric registry object
// if left empty, the whole json object is parsed as a metric registry
DropwizardMetricRegistryPath string
// an optional json path containing the default time of the metrics
// if left empty, the processing time is used
DropwizardTimePath string
// time format to use for parsing the time field
// defaults to time.RFC3339
DropwizardTimeFormat string
// an optional json path pointing to a json object with tag key/value pairs
// takes precedence over DropwizardTagPathsMap
DropwizardTagsPath string
// an optional map containing tag names as keys and json paths to retrieve the tag values from as values
// used if TagsPath is empty or doesn't return any tags
DropwizardTagPathsMap map[string]string
}
// NewParser returns a Parser interface based on the given config.
@@ -89,6 +106,10 @@ func NewParser(config *Config) (Parser, error) {
case "collectd":
parser, err = NewCollectdParser(config.CollectdAuthFile,
config.CollectdSecurityLevel, config.CollectdTypesDB)
case "dropwizard":
parser, err = NewDropwizardParser(config.DropwizardMetricRegistryPath,
config.DropwizardTimePath, config.DropwizardTimeFormat, config.DropwizardTagsPath, config.DropwizardTagPathsMap, config.DefaultTags,
config.Separator, config.Templates)
default:
err = fmt.Errorf("Invalid data format: %s", config.DataFormat)
}
@@ -143,3 +164,29 @@ func NewCollectdParser(
) (Parser, error) {
return collectd.NewCollectdParser(authFile, securityLevel, typesDB)
}
func NewDropwizardParser(
metricRegistryPath string,
timePath string,
timeFormat string,
tagsPath string,
tagPathsMap map[string]string,
defaultTags map[string]string,
separator string,
templates []string,
) (Parser, error) {
parser := &dropwizard.Parser{
MetricRegistryPath: metricRegistryPath,
TimePath: timePath,
TimeFormat: timeFormat,
TagsPath: tagsPath,
TagPathsMap: tagPathsMap,
DefaultTags: defaultTags,
Separator: separator,
Templates: templates,
}
err := parser.InitTemplating()
return parser, err
}