github.com/influxdata/telegraf@v1.30.3/parser.go (about) 1 package telegraf 2 3 // Parser is an interface defining functions that a parser plugin must satisfy. 4 type Parser interface { 5 // Parse takes a byte buffer separated by newlines 6 // ie, `cpu.usage.idle 90\ncpu.usage.busy 10` 7 // and parses it into telegraf metrics 8 // 9 // Must be thread-safe. 10 Parse(buf []byte) ([]Metric, error) 11 12 // ParseLine takes a single string metric 13 // ie, "cpu.usage.idle 90" 14 // and parses it into a telegraf metric. 15 // 16 // Must be thread-safe. 17 ParseLine(line string) (Metric, error) 18 19 // SetDefaultTags tells the parser to add all of the given tags 20 // to each parsed metric. 21 // NOTE: do _not_ modify the map after you've passed it here!! 22 SetDefaultTags(tags map[string]string) 23 } 24 25 type ParserFunc func() (Parser, error) 26 27 // ParserPlugin is an interface for plugins that are able to parse 28 // arbitrary data formats. 29 type ParserPlugin interface { 30 // SetParser sets the parser function for the interface 31 SetParser(parser Parser) 32 } 33 34 // ParserFuncPlugin is an interface for plugins that are able to parse 35 // arbitrary data formats. 36 type ParserFuncPlugin interface { 37 // GetParser returns a new parser. 38 SetParserFunc(fn ParserFunc) 39 }