2016-02-06 00:36:35 +00:00
|
|
|
package parsers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-09-18 16:23:45 +00:00
|
|
|
"time"
|
2016-02-06 00:36:35 +00:00
|
|
|
|
|
|
|
"github.com/influxdata/telegraf"
|
2017-04-12 17:41:26 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/collectd"
|
2018-08-24 23:40:41 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/csv"
|
2018-01-08 23:11:36 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/dropwizard"
|
2019-06-17 21:44:25 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/form_urlencoded"
|
2016-02-06 00:36:35 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/graphite"
|
2018-07-14 06:22:59 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/grok"
|
2016-02-06 00:36:35 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/influx"
|
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/json"
|
2018-08-22 20:55:41 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/logfmt"
|
2016-02-25 04:32:22 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/nagios"
|
2016-03-18 00:01:01 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/value"
|
2018-08-13 23:37:06 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/parsers/wavefront"
|
2016-02-06 00:36:35 +00:00
|
|
|
)
|
|
|
|
|
2018-09-18 16:23:45 +00:00
|
|
|
type ParserFunc func() (Parser, error)
|
|
|
|
|
2016-02-06 00:36:35 +00:00
|
|
|
// ParserInput is an interface for input plugins that are able to parse
|
|
|
|
// arbitrary data formats.
|
|
|
|
type ParserInput interface {
|
|
|
|
// SetParser sets the parser function for the interface
|
|
|
|
SetParser(parser Parser)
|
|
|
|
}
|
|
|
|
|
2018-09-18 16:23:45 +00:00
|
|
|
// ParserFuncInput is an interface for input plugins that are able to parse
|
|
|
|
// arbitrary data formats.
|
|
|
|
type ParserFuncInput interface {
|
|
|
|
// GetParser returns a new parser.
|
|
|
|
SetParserFunc(fn ParserFunc)
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:36:35 +00:00
|
|
|
// Parser is an interface defining functions that a parser plugin must satisfy.
|
|
|
|
type Parser interface {
|
|
|
|
// Parse takes a byte buffer separated by newlines
|
|
|
|
// ie, `cpu.usage.idle 90\ncpu.usage.busy 10`
|
|
|
|
// and parses it into telegraf metrics
|
2018-05-14 18:00:03 +00:00
|
|
|
//
|
|
|
|
// Must be thread-safe.
|
2016-02-06 00:36:35 +00:00
|
|
|
Parse(buf []byte) ([]telegraf.Metric, error)
|
|
|
|
|
|
|
|
// ParseLine takes a single string metric
|
|
|
|
// ie, "cpu.usage.idle 90"
|
|
|
|
// and parses it into a telegraf metric.
|
2018-05-14 18:00:03 +00:00
|
|
|
//
|
|
|
|
// Must be thread-safe.
|
2016-02-06 00:36:35 +00:00
|
|
|
ParseLine(line string) (telegraf.Metric, error)
|
2016-02-09 22:03:46 +00:00
|
|
|
|
|
|
|
// SetDefaultTags tells the parser to add all of the given tags
|
|
|
|
// to each parsed metric.
|
|
|
|
// NOTE: do _not_ modify the map after you've passed it here!!
|
|
|
|
SetDefaultTags(tags map[string]string)
|
2016-02-06 00:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2016-02-25 04:32:22 +00:00
|
|
|
// Dataformat can be one of: json, influx, graphite, value, nagios
|
2019-01-02 21:55:59 +00:00
|
|
|
DataFormat string `toml:"data_format"`
|
2016-02-06 00:36:35 +00:00
|
|
|
|
|
|
|
// Separator only applied to Graphite data.
|
2019-01-02 21:55:59 +00:00
|
|
|
Separator string `toml:"separator"`
|
2016-02-06 00:36:35 +00:00
|
|
|
// Templates only apply to Graphite data.
|
2019-01-02 21:55:59 +00:00
|
|
|
Templates []string `toml:"templates"`
|
2016-02-06 00:36:35 +00:00
|
|
|
|
|
|
|
// TagKeys only apply to JSON data
|
2019-01-02 21:55:59 +00:00
|
|
|
TagKeys []string `toml:"tag_keys"`
|
2019-07-15 23:48:19 +00:00
|
|
|
// Array of glob pattern strings keys that should be added as string fields.
|
2019-01-02 21:55:59 +00:00
|
|
|
JSONStringFields []string `toml:"json_string_fields"`
|
2018-08-23 02:26:48 +00:00
|
|
|
|
2019-01-02 21:55:59 +00:00
|
|
|
JSONNameKey string `toml:"json_name_key"`
|
2016-03-18 00:01:01 +00:00
|
|
|
// MetricName applies to JSON & value. This will be the name of the measurement.
|
2019-01-02 21:55:59 +00:00
|
|
|
MetricName string `toml:"metric_name"`
|
2016-02-06 00:36:35 +00:00
|
|
|
|
2018-08-23 02:26:48 +00:00
|
|
|
// holds a gjson path for json parser
|
2019-01-02 21:55:59 +00:00
|
|
|
JSONQuery string `toml:"json_query"`
|
2018-08-23 02:26:48 +00:00
|
|
|
|
|
|
|
// key of time
|
2019-01-02 21:55:59 +00:00
|
|
|
JSONTimeKey string `toml:"json_time_key"`
|
2018-08-23 02:26:48 +00:00
|
|
|
|
|
|
|
// time format
|
2019-01-02 21:55:59 +00:00
|
|
|
JSONTimeFormat string `toml:"json_time_format"`
|
2018-08-23 02:26:48 +00:00
|
|
|
|
2019-02-25 19:30:33 +00:00
|
|
|
// default timezone
|
|
|
|
JSONTimezone string `toml:"json_timezone"`
|
|
|
|
|
2019-10-23 21:06:39 +00:00
|
|
|
// Whether to continue if a JSON object can't be coerced
|
|
|
|
JSONStrict bool `toml:"json_strict"`
|
|
|
|
|
2017-04-12 17:41:26 +00:00
|
|
|
// Authentication file for collectd
|
2019-01-02 21:55:59 +00:00
|
|
|
CollectdAuthFile string `toml:"collectd_auth_file"`
|
2017-04-12 17:41:26 +00:00
|
|
|
// One of none (default), sign, or encrypt
|
2019-01-02 21:55:59 +00:00
|
|
|
CollectdSecurityLevel string `toml:"collectd_security_level"`
|
2017-04-12 17:41:26 +00:00
|
|
|
// Dataset specification for collectd
|
2019-01-02 21:55:59 +00:00
|
|
|
CollectdTypesDB []string `toml:"collectd_types_db"`
|
2017-04-12 17:41:26 +00:00
|
|
|
|
2018-07-12 00:29:23 +00:00
|
|
|
// whether to split or join multivalue metrics
|
2019-01-02 21:55:59 +00:00
|
|
|
CollectdSplit string `toml:"collectd_split"`
|
2018-07-12 00:29:23 +00:00
|
|
|
|
2016-03-18 00:01:01 +00:00
|
|
|
// DataType only applies to value, this will be the type to parse value to
|
2019-01-02 21:55:59 +00:00
|
|
|
DataType string `toml:"data_type"`
|
2016-03-18 00:01:01 +00:00
|
|
|
|
2016-02-06 00:36:35 +00:00
|
|
|
// DefaultTags are the default tags that will be added to all parsed metrics.
|
2019-01-02 21:55:59 +00:00
|
|
|
DefaultTags map[string]string `toml:"default_tags"`
|
2018-01-08 23:11:36 +00:00
|
|
|
|
|
|
|
// an optional json path containing the metric registry object
|
|
|
|
// if left empty, the whole json object is parsed as a metric registry
|
2019-01-02 21:55:59 +00:00
|
|
|
DropwizardMetricRegistryPath string `toml:"dropwizard_metric_registry_path"`
|
2018-01-08 23:11:36 +00:00
|
|
|
// an optional json path containing the default time of the metrics
|
|
|
|
// if left empty, the processing time is used
|
2019-01-02 21:55:59 +00:00
|
|
|
DropwizardTimePath string `toml:"dropwizard_time_path"`
|
2018-01-08 23:11:36 +00:00
|
|
|
// time format to use for parsing the time field
|
|
|
|
// defaults to time.RFC3339
|
2019-01-02 21:55:59 +00:00
|
|
|
DropwizardTimeFormat string `toml:"dropwizard_time_format"`
|
2018-01-08 23:11:36 +00:00
|
|
|
// an optional json path pointing to a json object with tag key/value pairs
|
|
|
|
// takes precedence over DropwizardTagPathsMap
|
2019-01-02 21:55:59 +00:00
|
|
|
DropwizardTagsPath string `toml:"dropwizard_tags_path"`
|
2018-01-08 23:11:36 +00:00
|
|
|
// 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
|
2019-01-02 21:55:59 +00:00
|
|
|
DropwizardTagPathsMap map[string]string `toml:"dropwizard_tag_paths_map"`
|
2018-07-14 06:22:59 +00:00
|
|
|
|
|
|
|
//grok patterns
|
2019-01-02 21:55:59 +00:00
|
|
|
GrokPatterns []string `toml:"grok_patterns"`
|
|
|
|
GrokNamedPatterns []string `toml:"grok_named_patterns"`
|
|
|
|
GrokCustomPatterns string `toml:"grok_custom_patterns"`
|
|
|
|
GrokCustomPatternFiles []string `toml:"grok_custom_pattern_files"`
|
|
|
|
GrokTimezone string `toml:"grok_timezone"`
|
2019-02-27 01:35:57 +00:00
|
|
|
GrokUniqueTimestamp string `toml:"grok_unique_timestamp"`
|
2018-08-24 23:40:41 +00:00
|
|
|
|
|
|
|
//csv configuration
|
2018-09-18 16:23:45 +00:00
|
|
|
CSVColumnNames []string `toml:"csv_column_names"`
|
2018-10-04 01:19:44 +00:00
|
|
|
CSVColumnTypes []string `toml:"csv_column_types"`
|
2018-09-18 16:23:45 +00:00
|
|
|
CSVComment string `toml:"csv_comment"`
|
|
|
|
CSVDelimiter string `toml:"csv_delimiter"`
|
|
|
|
CSVHeaderRowCount int `toml:"csv_header_row_count"`
|
|
|
|
CSVMeasurementColumn string `toml:"csv_measurement_column"`
|
|
|
|
CSVSkipColumns int `toml:"csv_skip_columns"`
|
|
|
|
CSVSkipRows int `toml:"csv_skip_rows"`
|
|
|
|
CSVTagColumns []string `toml:"csv_tag_columns"`
|
|
|
|
CSVTimestampColumn string `toml:"csv_timestamp_column"`
|
|
|
|
CSVTimestampFormat string `toml:"csv_timestamp_format"`
|
|
|
|
CSVTrimSpace bool `toml:"csv_trim_space"`
|
2019-06-17 20:34:54 +00:00
|
|
|
|
|
|
|
// FormData configuration
|
2019-06-17 21:44:25 +00:00
|
|
|
FormUrlencodedTagKeys []string `toml:"form_urlencoded_tag_keys"`
|
2016-02-06 00:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewParser returns a Parser interface based on the given config.
|
|
|
|
func NewParser(config *Config) (Parser, error) {
|
|
|
|
var err error
|
|
|
|
var parser Parser
|
|
|
|
switch config.DataFormat {
|
|
|
|
case "json":
|
2019-07-15 23:48:19 +00:00
|
|
|
parser, err = json.New(
|
|
|
|
&json.Config{
|
|
|
|
MetricName: config.MetricName,
|
|
|
|
TagKeys: config.TagKeys,
|
|
|
|
NameKey: config.JSONNameKey,
|
|
|
|
StringFields: config.JSONStringFields,
|
|
|
|
Query: config.JSONQuery,
|
|
|
|
TimeKey: config.JSONTimeKey,
|
|
|
|
TimeFormat: config.JSONTimeFormat,
|
|
|
|
Timezone: config.JSONTimezone,
|
|
|
|
DefaultTags: config.DefaultTags,
|
2019-10-23 21:06:39 +00:00
|
|
|
Strict: config.JSONStrict,
|
2019-07-15 23:48:19 +00:00
|
|
|
},
|
|
|
|
)
|
2016-03-18 00:01:01 +00:00
|
|
|
case "value":
|
|
|
|
parser, err = NewValueParser(config.MetricName,
|
|
|
|
config.DataType, config.DefaultTags)
|
2016-02-06 00:36:35 +00:00
|
|
|
case "influx":
|
|
|
|
parser, err = NewInfluxParser()
|
2016-02-25 04:32:22 +00:00
|
|
|
case "nagios":
|
|
|
|
parser, err = NewNagiosParser()
|
2016-02-06 00:36:35 +00:00
|
|
|
case "graphite":
|
|
|
|
parser, err = NewGraphiteParser(config.Separator,
|
|
|
|
config.Templates, config.DefaultTags)
|
2017-04-12 17:41:26 +00:00
|
|
|
case "collectd":
|
|
|
|
parser, err = NewCollectdParser(config.CollectdAuthFile,
|
2018-07-12 00:29:23 +00:00
|
|
|
config.CollectdSecurityLevel, config.CollectdTypesDB, config.CollectdSplit)
|
2018-01-08 23:11:36 +00:00
|
|
|
case "dropwizard":
|
2018-05-14 18:00:03 +00:00
|
|
|
parser, err = NewDropwizardParser(
|
|
|
|
config.DropwizardMetricRegistryPath,
|
|
|
|
config.DropwizardTimePath,
|
|
|
|
config.DropwizardTimeFormat,
|
|
|
|
config.DropwizardTagsPath,
|
|
|
|
config.DropwizardTagPathsMap,
|
|
|
|
config.DefaultTags,
|
|
|
|
config.Separator,
|
|
|
|
config.Templates)
|
2018-08-13 23:37:06 +00:00
|
|
|
case "wavefront":
|
|
|
|
parser, err = NewWavefrontParser(config.DefaultTags)
|
2018-07-14 06:22:59 +00:00
|
|
|
case "grok":
|
|
|
|
parser, err = newGrokParser(
|
|
|
|
config.MetricName,
|
|
|
|
config.GrokPatterns,
|
|
|
|
config.GrokNamedPatterns,
|
|
|
|
config.GrokCustomPatterns,
|
|
|
|
config.GrokCustomPatternFiles,
|
2019-02-27 01:35:57 +00:00
|
|
|
config.GrokTimezone,
|
|
|
|
config.GrokUniqueTimestamp)
|
2018-08-24 23:40:41 +00:00
|
|
|
case "csv":
|
|
|
|
parser, err = newCSVParser(config.MetricName,
|
|
|
|
config.CSVHeaderRowCount,
|
|
|
|
config.CSVSkipRows,
|
|
|
|
config.CSVSkipColumns,
|
|
|
|
config.CSVDelimiter,
|
|
|
|
config.CSVComment,
|
|
|
|
config.CSVTrimSpace,
|
|
|
|
config.CSVColumnNames,
|
2018-10-04 01:19:44 +00:00
|
|
|
config.CSVColumnTypes,
|
2018-08-24 23:40:41 +00:00
|
|
|
config.CSVTagColumns,
|
|
|
|
config.CSVMeasurementColumn,
|
|
|
|
config.CSVTimestampColumn,
|
|
|
|
config.CSVTimestampFormat,
|
|
|
|
config.DefaultTags)
|
2018-08-22 20:55:41 +00:00
|
|
|
case "logfmt":
|
|
|
|
parser, err = NewLogFmtParser(config.MetricName, config.DefaultTags)
|
2019-06-17 21:44:25 +00:00
|
|
|
case "form_urlencoded":
|
|
|
|
parser, err = NewFormUrlencodedParser(
|
2019-06-17 20:34:54 +00:00
|
|
|
config.MetricName,
|
|
|
|
config.DefaultTags,
|
2019-06-17 21:44:25 +00:00
|
|
|
config.FormUrlencodedTagKeys,
|
2019-06-17 20:34:54 +00:00
|
|
|
)
|
2016-02-06 00:36:35 +00:00
|
|
|
default:
|
|
|
|
err = fmt.Errorf("Invalid data format: %s", config.DataFormat)
|
|
|
|
}
|
|
|
|
return parser, err
|
|
|
|
}
|
|
|
|
|
2018-08-24 23:40:41 +00:00
|
|
|
func newCSVParser(metricName string,
|
2018-09-18 16:23:45 +00:00
|
|
|
headerRowCount int,
|
2018-08-24 23:40:41 +00:00
|
|
|
skipRows int,
|
|
|
|
skipColumns int,
|
|
|
|
delimiter string,
|
|
|
|
comment string,
|
|
|
|
trimSpace bool,
|
2018-09-18 16:23:45 +00:00
|
|
|
columnNames []string,
|
2018-10-04 01:19:44 +00:00
|
|
|
columnTypes []string,
|
2018-08-24 23:40:41 +00:00
|
|
|
tagColumns []string,
|
|
|
|
nameColumn string,
|
|
|
|
timestampColumn string,
|
|
|
|
timestampFormat string,
|
|
|
|
defaultTags map[string]string) (Parser, error) {
|
|
|
|
|
2018-09-18 16:23:45 +00:00
|
|
|
if headerRowCount == 0 && len(columnNames) == 0 {
|
2018-11-19 19:27:21 +00:00
|
|
|
return nil, fmt.Errorf("`csv_header_row_count` must be defined if `csv_column_names` is not specified")
|
2018-08-24 23:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if delimiter != "" {
|
|
|
|
runeStr := []rune(delimiter)
|
|
|
|
if len(runeStr) > 1 {
|
2018-09-18 16:23:45 +00:00
|
|
|
return nil, fmt.Errorf("csv_delimiter must be a single character, got: %s", delimiter)
|
2018-08-24 23:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if comment != "" {
|
|
|
|
runeStr := []rune(comment)
|
|
|
|
if len(runeStr) > 1 {
|
2018-09-18 16:23:45 +00:00
|
|
|
return nil, fmt.Errorf("csv_delimiter must be a single character, got: %s", comment)
|
2018-08-24 23:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 01:19:44 +00:00
|
|
|
if len(columnNames) > 0 && len(columnTypes) > 0 && len(columnNames) != len(columnTypes) {
|
|
|
|
return nil, fmt.Errorf("csv_column_names field count doesn't match with csv_column_types")
|
|
|
|
}
|
|
|
|
|
2018-08-24 23:40:41 +00:00
|
|
|
parser := &csv.Parser{
|
|
|
|
MetricName: metricName,
|
2018-09-18 16:23:45 +00:00
|
|
|
HeaderRowCount: headerRowCount,
|
2018-08-24 23:40:41 +00:00
|
|
|
SkipRows: skipRows,
|
|
|
|
SkipColumns: skipColumns,
|
|
|
|
Delimiter: delimiter,
|
|
|
|
Comment: comment,
|
|
|
|
TrimSpace: trimSpace,
|
2018-09-18 16:23:45 +00:00
|
|
|
ColumnNames: columnNames,
|
2018-10-04 01:19:44 +00:00
|
|
|
ColumnTypes: columnTypes,
|
2018-08-24 23:40:41 +00:00
|
|
|
TagColumns: tagColumns,
|
|
|
|
MeasurementColumn: nameColumn,
|
|
|
|
TimestampColumn: timestampColumn,
|
|
|
|
TimestampFormat: timestampFormat,
|
|
|
|
DefaultTags: defaultTags,
|
2018-09-18 16:23:45 +00:00
|
|
|
TimeFunc: time.Now,
|
2018-08-24 23:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parser, nil
|
|
|
|
}
|
|
|
|
|
2018-07-14 06:22:59 +00:00
|
|
|
func newGrokParser(metricName string,
|
2019-02-27 01:35:57 +00:00
|
|
|
patterns []string, nPatterns []string,
|
|
|
|
cPatterns string, cPatternFiles []string,
|
|
|
|
tZone string, uniqueTimestamp string) (Parser, error) {
|
2018-07-14 06:22:59 +00:00
|
|
|
parser := grok.Parser{
|
|
|
|
Measurement: metricName,
|
|
|
|
Patterns: patterns,
|
|
|
|
NamedPatterns: nPatterns,
|
|
|
|
CustomPatterns: cPatterns,
|
|
|
|
CustomPatternFiles: cPatternFiles,
|
|
|
|
Timezone: tZone,
|
2019-02-27 01:35:57 +00:00
|
|
|
UniqueTimestamp: uniqueTimestamp,
|
2018-07-14 06:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err := parser.Compile()
|
|
|
|
return &parser, err
|
|
|
|
}
|
|
|
|
|
2016-02-25 04:32:22 +00:00
|
|
|
func NewNagiosParser() (Parser, error) {
|
|
|
|
return &nagios.NagiosParser{}, nil
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:36:35 +00:00
|
|
|
func NewInfluxParser() (Parser, error) {
|
2018-03-28 00:30:51 +00:00
|
|
|
handler := influx.NewMetricHandler()
|
|
|
|
return influx.NewParser(handler), nil
|
2016-02-06 00:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewGraphiteParser(
|
|
|
|
separator string,
|
|
|
|
templates []string,
|
|
|
|
defaultTags map[string]string,
|
|
|
|
) (Parser, error) {
|
|
|
|
return graphite.NewGraphiteParser(separator, templates, defaultTags)
|
|
|
|
}
|
2016-03-18 00:01:01 +00:00
|
|
|
|
|
|
|
func NewValueParser(
|
|
|
|
metricName string,
|
|
|
|
dataType string,
|
|
|
|
defaultTags map[string]string,
|
|
|
|
) (Parser, error) {
|
|
|
|
return &value.ValueParser{
|
|
|
|
MetricName: metricName,
|
|
|
|
DataType: dataType,
|
|
|
|
DefaultTags: defaultTags,
|
|
|
|
}, nil
|
|
|
|
}
|
2017-04-12 17:41:26 +00:00
|
|
|
|
|
|
|
func NewCollectdParser(
|
|
|
|
authFile string,
|
|
|
|
securityLevel string,
|
|
|
|
typesDB []string,
|
2018-07-12 00:29:23 +00:00
|
|
|
split string,
|
2017-04-12 17:41:26 +00:00
|
|
|
) (Parser, error) {
|
2018-07-12 00:29:23 +00:00
|
|
|
return collectd.NewCollectdParser(authFile, securityLevel, typesDB, split)
|
2017-04-12 17:41:26 +00:00
|
|
|
}
|
2018-01-08 23:11:36 +00:00
|
|
|
|
|
|
|
func NewDropwizardParser(
|
|
|
|
metricRegistryPath string,
|
|
|
|
timePath string,
|
|
|
|
timeFormat string,
|
|
|
|
tagsPath string,
|
|
|
|
tagPathsMap map[string]string,
|
|
|
|
defaultTags map[string]string,
|
|
|
|
separator string,
|
|
|
|
templates []string,
|
|
|
|
|
|
|
|
) (Parser, error) {
|
2018-05-14 18:00:03 +00:00
|
|
|
parser := dropwizard.NewParser()
|
|
|
|
parser.MetricRegistryPath = metricRegistryPath
|
|
|
|
parser.TimePath = timePath
|
|
|
|
parser.TimeFormat = timeFormat
|
|
|
|
parser.TagsPath = tagsPath
|
|
|
|
parser.TagPathsMap = tagPathsMap
|
|
|
|
parser.DefaultTags = defaultTags
|
|
|
|
err := parser.SetTemplates(separator, templates)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-01-08 23:11:36 +00:00
|
|
|
}
|
|
|
|
return parser, err
|
|
|
|
}
|
2018-08-13 23:37:06 +00:00
|
|
|
|
2018-08-22 20:55:41 +00:00
|
|
|
// NewLogFmtParser returns a logfmt parser with the default options.
|
|
|
|
func NewLogFmtParser(metricName string, defaultTags map[string]string) (Parser, error) {
|
|
|
|
return logfmt.NewParser(metricName, defaultTags), nil
|
|
|
|
}
|
|
|
|
|
2018-08-13 23:37:06 +00:00
|
|
|
func NewWavefrontParser(defaultTags map[string]string) (Parser, error) {
|
|
|
|
return wavefront.NewWavefrontParser(defaultTags), nil
|
|
|
|
}
|
2019-06-17 20:34:54 +00:00
|
|
|
|
2019-06-17 21:44:25 +00:00
|
|
|
func NewFormUrlencodedParser(
|
2019-06-17 20:34:54 +00:00
|
|
|
metricName string,
|
|
|
|
defaultTags map[string]string,
|
|
|
|
tagKeys []string,
|
|
|
|
) (Parser, error) {
|
2019-06-17 21:44:25 +00:00
|
|
|
return &form_urlencoded.Parser{
|
2019-06-17 20:34:54 +00:00
|
|
|
MetricName: metricName,
|
|
|
|
DefaultTags: defaultTags,
|
|
|
|
TagKeys: tagKeys,
|
|
|
|
}, nil
|
|
|
|
}
|