Removed the Tags capability from the graphite parser.
This commit is contained in:
parent
5b29df75f5
commit
14f2f36383
|
@ -3,8 +3,6 @@ package graphite
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/influxdata/influxdb/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -16,30 +14,15 @@ const (
|
||||||
// Config represents the configuration for Graphite endpoints.
|
// Config represents the configuration for Graphite endpoints.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Separator string
|
Separator string
|
||||||
Tags []string
|
|
||||||
Templates []string
|
Templates []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultTags returns the config's tags.
|
|
||||||
func (c *Config) DefaultTags() models.Tags {
|
|
||||||
tags := models.Tags{}
|
|
||||||
for _, t := range c.Tags {
|
|
||||||
parts := strings.Split(t, "=")
|
|
||||||
tags[parts[0]] = parts[1]
|
|
||||||
}
|
|
||||||
return tags
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate validates the config's templates and tags.
|
// Validate validates the config's templates and tags.
|
||||||
func (c *Config) Validate() error {
|
func (c *Config) Validate() error {
|
||||||
if err := c.validateTemplates(); err != nil {
|
if err := c.validateTemplates(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.validateTags(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,15 +93,6 @@ func (c *Config) validateTemplates() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) validateTags() error {
|
|
||||||
for _, t := range c.Tags {
|
|
||||||
if err := c.validateTag(t); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) validateTemplate(template string) error {
|
func (c *Config) validateTemplate(template string) error {
|
||||||
hasMeasurement := false
|
hasMeasurement := false
|
||||||
for _, p := range strings.Split(template, ".") {
|
for _, p := range strings.Split(template, ".") {
|
||||||
|
|
|
@ -35,14 +35,12 @@ func init() {
|
||||||
// Parser encapsulates a Graphite Parser.
|
// Parser encapsulates a Graphite Parser.
|
||||||
type Parser struct {
|
type Parser struct {
|
||||||
matcher *matcher
|
matcher *matcher
|
||||||
tags models.Tags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options are configurable values that can be provided to a Parser
|
// Options are configurable values that can be provided to a Parser
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Separator string
|
Separator string
|
||||||
Templates []string
|
Templates []string
|
||||||
DefaultTags models.Tags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewParserWithOptions returns a graphite parser using the given options
|
// NewParserWithOptions returns a graphite parser using the given options
|
||||||
|
@ -84,15 +82,14 @@ func NewParserWithOptions(options Options) (*Parser, error) {
|
||||||
}
|
}
|
||||||
matcher.Add(filter, tmpl)
|
matcher.Add(filter, tmpl)
|
||||||
}
|
}
|
||||||
return &Parser{matcher: matcher, tags: options.DefaultTags}, nil
|
return &Parser{matcher: matcher}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewParser returns a GraphiteParser instance.
|
// NewParser returns a GraphiteParser instance.
|
||||||
func NewParser(templates []string, defaultTags models.Tags) (*Parser, error) {
|
func NewParser(templates []string) (*Parser, error) {
|
||||||
return NewParserWithOptions(
|
return NewParserWithOptions(
|
||||||
Options{
|
Options{
|
||||||
Templates: templates,
|
Templates: templates,
|
||||||
DefaultTags: defaultTags,
|
|
||||||
Separator: DefaultSeparator,
|
Separator: DefaultSeparator,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -182,12 +179,6 @@ func (p *Parser) Parse(line string) (telegraf.Metric, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the default tags on the point if they are not already set
|
|
||||||
for k, v := range p.tags {
|
|
||||||
if _, ok := tags[k]; !ok {
|
|
||||||
tags[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return telegraf.NewMetric(measurement, tags, fieldValues, timestamp)
|
return telegraf.NewMetric(measurement, tags, fieldValues, timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,12 +193,7 @@ func (p *Parser) ApplyTemplate(line string) (string, map[string]string, string,
|
||||||
// decode the name and tags
|
// decode the name and tags
|
||||||
template := p.matcher.Match(fields[0])
|
template := p.matcher.Match(fields[0])
|
||||||
name, tags, field, err := template.Apply(fields[0])
|
name, tags, field, err := template.Apply(fields[0])
|
||||||
// Set the default tags on the point if they are not already set
|
|
||||||
for k, v := range p.tags {
|
|
||||||
if _, ok := tags[k]; !ok {
|
|
||||||
tags[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return name, tags, field, err
|
return name, tags, field, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,19 +44,15 @@ and strings will be ignored.
|
||||||
### If matching multiple measurement files, this string will be used to join the matched values.
|
### If matching multiple measurement files, this string will be used to join the matched values.
|
||||||
#separator = "."
|
#separator = "."
|
||||||
|
|
||||||
### Default tags that will be added to all metrics. These can be overridden at the template level
|
|
||||||
### or by tags extracted from metric
|
|
||||||
#tags = ["region=north-east", "zone=1c"]
|
|
||||||
|
|
||||||
### Each template line requires a template pattern. It can have an optional
|
### Each template line requires a template pattern. It can have an optional
|
||||||
### filter before the template and separated by spaces. It can also have optional extra
|
### filter before the template and separated by spaces. It can also have optional extra
|
||||||
### tags following the template. Multiple tags should be separated by commas and no spaces
|
### tags following the template. Multiple tags should be separated by commas and no spaces
|
||||||
### similar to the line protocol format. The can be only one default template.
|
### similar to the line protocol format. The can be only one default template.
|
||||||
### Templates support below format:
|
### Templates support below format:
|
||||||
### filter + template
|
### 1. filter + template
|
||||||
### filter + template + extra tag
|
### 2. filter + template + extra tag
|
||||||
### filter + template with field key
|
### 3. filter + template with field key
|
||||||
### default template. Ignore the first graphite component "servers"
|
### 4. default template
|
||||||
#templates = [
|
#templates = [
|
||||||
# "*.app env.service.resource.measurement",
|
# "*.app env.service.resource.measurement",
|
||||||
# "stats.* .host.measurement* region=us-west,agent=sensu",
|
# "stats.* .host.measurement* region=us-west,agent=sensu",
|
||||||
|
@ -149,19 +145,15 @@ We can also change the data_format to "graphite" to use the metrics collecting s
|
||||||
### If matching multiple measurement files, this string will be used to join the matched values.
|
### If matching multiple measurement files, this string will be used to join the matched values.
|
||||||
separator = "."
|
separator = "."
|
||||||
|
|
||||||
### Default tags that will be added to all metrics. These can be overridden at the template level
|
|
||||||
### or by tags extracted from metric
|
|
||||||
tags = ["region=north-east", "zone=1c"]
|
|
||||||
|
|
||||||
### Each template line requires a template pattern. It can have an optional
|
### Each template line requires a template pattern. It can have an optional
|
||||||
### filter before the template and separated by spaces. It can also have optional extra
|
### filter before the template and separated by spaces. It can also have optional extra
|
||||||
### tags following the template. Multiple tags should be separated by commas and no spaces
|
### tags following the template. Multiple tags should be separated by commas and no spaces
|
||||||
### similar to the line protocol format. The can be only one default template.
|
### similar to the line protocol format. The can be only one default template.
|
||||||
### Templates support below format:
|
### Templates support below format:
|
||||||
### filter + template
|
### 1. filter + template
|
||||||
### filter + template + extra tag
|
### 2. filter + template + extra tag
|
||||||
### filter + template with field key
|
### 3. filter + template with field key
|
||||||
### default template. Ignore the first graphite component "servers"
|
### 4. default template
|
||||||
templates = [
|
templates = [
|
||||||
"*.app env.service.resource.measurement",
|
"*.app env.service.resource.measurement",
|
||||||
"stats.* .host.measurement* region=us-west,agent=sensu",
|
"stats.* .host.measurement* region=us-west,agent=sensu",
|
||||||
|
|
|
@ -4,12 +4,6 @@ import (
|
||||||
"github.com/influxdata/telegraf/internal/encoding/graphite"
|
"github.com/influxdata/telegraf/internal/encoding/graphite"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
// DefaultSeparator is the default join character to use when joining multiple
|
|
||||||
// measurment parts in a template.
|
|
||||||
DefaultSeparator = "."
|
|
||||||
)
|
|
||||||
|
|
||||||
// Config represents the configuration for Graphite endpoints.
|
// Config represents the configuration for Graphite endpoints.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Commands []string
|
Commands []string
|
||||||
|
@ -17,21 +11,15 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New Config instance.
|
// New Config instance.
|
||||||
func NewConfig(commands, tags, templates []string, separator string) *Config {
|
func NewConfig(commands, templates []string, separator string) *Config {
|
||||||
c := &Config{}
|
c := &Config{}
|
||||||
c.Commands = commands
|
if separator == "" {
|
||||||
c.Tags = tags
|
separator = graphite.DefaultSeparator
|
||||||
c.Templates = templates
|
|
||||||
c.Separator = separator
|
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDefaults takes the given config and returns a new config with any required
|
c.Commands = commands
|
||||||
// default values set.
|
c.Templates = templates
|
||||||
func (c *Config) WithDefaults() *Config {
|
c.Separator = separator
|
||||||
d := *c
|
|
||||||
if d.Separator == "" {
|
return c
|
||||||
d.Separator = DefaultSeparator
|
|
||||||
}
|
|
||||||
return &d
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,19 +32,15 @@ const sampleConfig = `
|
||||||
### If matching multiple measurement files, this string will be used to join the matched values.
|
### If matching multiple measurement files, this string will be used to join the matched values.
|
||||||
separator = "."
|
separator = "."
|
||||||
|
|
||||||
### Default tags that will be added to all metrics. These can be overridden at the template level
|
|
||||||
### or by tags extracted from metric
|
|
||||||
tags = ["region=north-east", "zone=1c"]
|
|
||||||
|
|
||||||
### Each template line requires a template pattern. It can have an optional
|
### Each template line requires a template pattern. It can have an optional
|
||||||
### filter before the template and separated by spaces. It can also have optional extra
|
### filter before the template and separated by spaces. It can also have optional extra
|
||||||
### tags following the template. Multiple tags should be separated by commas and no spaces
|
### tags following the template. Multiple tags should be separated by commas and no spaces
|
||||||
### similar to the line protocol format. The can be only one default template.
|
### similar to the line protocol format. The can be only one default template.
|
||||||
### Templates support below format:
|
### Templates support below format:
|
||||||
### filter + template
|
### 1. filter + template
|
||||||
### filter + template + extra tag
|
### 2. filter + template + extra tag
|
||||||
### filter + template with field key
|
### 3. filter + template with field key
|
||||||
### default template. Ignore the first graphite component "servers"
|
### 4. default template
|
||||||
templates = [
|
templates = [
|
||||||
"*.app env.service.resource.measurement",
|
"*.app env.service.resource.measurement",
|
||||||
"stats.* .host.measurement* region=us-west,agent=sensu",
|
"stats.* .host.measurement* region=us-west,agent=sensu",
|
||||||
|
@ -59,7 +55,6 @@ type Exec struct {
|
||||||
DataFormat string
|
DataFormat string
|
||||||
|
|
||||||
Separator string
|
Separator string
|
||||||
Tags []string
|
|
||||||
Templates []string
|
Templates []string
|
||||||
|
|
||||||
encodingParser *encoding.Parser
|
encodingParser *encoding.Parser
|
||||||
|
@ -125,8 +120,7 @@ func (e *Exec) initConfig() error {
|
||||||
e.Commands = []string{e.Command}
|
e.Commands = []string{e.Command}
|
||||||
}
|
}
|
||||||
|
|
||||||
c := NewConfig(e.Commands, e.Tags, e.Templates, e.Separator)
|
c := NewConfig(e.Commands, e.Templates, e.Separator)
|
||||||
c.WithDefaults()
|
|
||||||
if err := c.Validate(); err != nil {
|
if err := c.Validate(); err != nil {
|
||||||
return fmt.Errorf("exec configuration is error: %s ", err.Error())
|
return fmt.Errorf("exec configuration is error: %s ", err.Error())
|
||||||
|
|
||||||
|
@ -135,7 +129,6 @@ func (e *Exec) initConfig() error {
|
||||||
|
|
||||||
graphiteParser, err := graphite.NewParserWithOptions(graphite.Options{
|
graphiteParser, err := graphite.NewParserWithOptions(graphite.Options{
|
||||||
Templates: e.config.Templates,
|
Templates: e.config.Templates,
|
||||||
DefaultTags: e.config.DefaultTags(),
|
|
||||||
Separator: e.config.Separator})
|
Separator: e.config.Separator})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -152,7 +145,7 @@ func (e *Exec) SampleConfig() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Exec) Description() string {
|
func (e *Exec) Description() string {
|
||||||
return "Read metrics from one or more commands that output graphite line protocol to stdout"
|
return "Read metrics from one or more commands that can output JSON, influx or graphite line protocol to stdout"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Exec) Gather(acc telegraf.Accumulator) error {
|
func (e *Exec) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
|
@ -8,7 +8,7 @@ size limit, [see here for more details.](../udp/README.md#a-note-on-udpip-os-buf
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Each Socket input allows the binding address, and protocol to be set.
|
Each Socket input allows the binding address, and protocol to be set.
|
||||||
Currently socket service input only support line protocol formats of metric: influx and graphite.
|
Currently socket service input only support two line protocol formats of metric: influx and graphite.
|
||||||
Each input allows to use data_format to choose which format of contents will be sent to this socket service.
|
Each input allows to use data_format to choose which format of contents will be sent to this socket service.
|
||||||
|
|
||||||
## Parsing Metrics
|
## Parsing Metrics
|
||||||
|
@ -142,19 +142,15 @@ If you need to add the same set of tags to all metrics, you can define them glob
|
||||||
### If matching multiple measurement files, this string will be used to join the matched values.
|
### If matching multiple measurement files, this string will be used to join the matched values.
|
||||||
separator = "."
|
separator = "."
|
||||||
|
|
||||||
### Default tags that will be added to all metrics. These can be overridden at the template level
|
|
||||||
### or by tags extracted from metric
|
|
||||||
tags = ["region=us-east", "zone=1c"]
|
|
||||||
|
|
||||||
### Each template line requires a template pattern. It can have an optional
|
### Each template line requires a template pattern. It can have an optional
|
||||||
### filter before the template and separated by spaces. It can also have optional extra
|
### filter before the template and separated by spaces. It can also have optional extra
|
||||||
### tags following the template. Multiple tags should be separated by commas and no spaces
|
### tags following the template. Multiple tags should be separated by commas and no spaces
|
||||||
### similar to the line protocol format. The can be only one default template.
|
### similar to the line protocol format. The can be only one default template.
|
||||||
### Templates support below format:
|
### Templates support below format:
|
||||||
### filter + template
|
### 1. filter + template
|
||||||
### filter + template + extra tag
|
### 2. filter + template + extra tag
|
||||||
### filter + template with field key
|
### 3. filter + template with field key
|
||||||
### default template. Ignore the first graphite component "servers"
|
### 4. default template
|
||||||
templates = [
|
templates = [
|
||||||
"*.app env.service.resource.measurement",
|
"*.app env.service.resource.measurement",
|
||||||
"stats.* .host.measurement* region=us-west,agent=sensu",
|
"stats.* .host.measurement* region=us-west,agent=sensu",
|
||||||
|
|
|
@ -9,10 +9,6 @@ const (
|
||||||
// DefaultProtocol is the default IP protocol used by the Graphite input.
|
// DefaultProtocol is the default IP protocol used by the Graphite input.
|
||||||
DefaultProtocol = "tcp"
|
DefaultProtocol = "tcp"
|
||||||
|
|
||||||
// DefaultSeparator is the default join character to use when joining multiple
|
|
||||||
// measurment parts in a template.
|
|
||||||
DefaultSeparator = "."
|
|
||||||
|
|
||||||
// DefaultUDPReadBuffer is the default buffer size for the UDP listener.
|
// DefaultUDPReadBuffer is the default buffer size for the UDP listener.
|
||||||
// Sets the size of the operating system's receive buffer associated with
|
// Sets the size of the operating system's receive buffer associated with
|
||||||
// the UDP traffic. Keep in mind that the OS must be able
|
// the UDP traffic. Keep in mind that the OS must be able
|
||||||
|
@ -36,34 +32,26 @@ type Config struct {
|
||||||
graphite.Config
|
graphite.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDefaults takes the given config and returns a new config with any required
|
// New Config instance.
|
||||||
// default values set.
|
func NewConfig(bindAddress, protocol string, udpReadBuffer int, separator string, templates []string) *Config {
|
||||||
func (c *Config) WithDefaults() *Config {
|
c := &Config{}
|
||||||
d := *c
|
if bindAddress == "" {
|
||||||
if d.BindAddress == "" {
|
bindAddress = DefaultBindAddress
|
||||||
d.BindAddress = DefaultBindAddress
|
|
||||||
}
|
}
|
||||||
if d.Protocol == "" {
|
if protocol == "" {
|
||||||
d.Protocol = DefaultProtocol
|
protocol = DefaultProtocol
|
||||||
}
|
}
|
||||||
if d.Separator == "" {
|
if udpReadBuffer < 0 {
|
||||||
d.Separator = DefaultSeparator
|
udpReadBuffer = DefaultUdpReadBuffer
|
||||||
}
|
}
|
||||||
if d.UdpReadBuffer == 0 {
|
if separator == "" {
|
||||||
d.UdpReadBuffer = DefaultUdpReadBuffer
|
separator = graphite.DefaultSeparator
|
||||||
}
|
|
||||||
return &d
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New Config instance.
|
|
||||||
func NewConfig(bindAddress, protocol string, udpReadBuffer int, separator string, tags []string, templates []string) *Config {
|
|
||||||
c := &Config{}
|
|
||||||
c.BindAddress = bindAddress
|
c.BindAddress = bindAddress
|
||||||
c.Protocol = protocol
|
c.Protocol = protocol
|
||||||
c.UdpReadBuffer = udpReadBuffer
|
c.UdpReadBuffer = udpReadBuffer
|
||||||
|
|
||||||
c.Separator = separator
|
c.Separator = separator
|
||||||
c.Tags = tags
|
|
||||||
c.Templates = templates
|
c.Templates = templates
|
||||||
|
|
||||||
return c
|
return c
|
||||||
|
|
|
@ -40,7 +40,6 @@ type Socket struct {
|
||||||
DataFormat string
|
DataFormat string
|
||||||
|
|
||||||
Separator string
|
Separator string
|
||||||
Tags []string
|
|
||||||
Templates []string
|
Templates []string
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
|
@ -76,19 +75,15 @@ var sampleConfig = `
|
||||||
### If matching multiple measurement files, this string will be used to join the matched values.
|
### If matching multiple measurement files, this string will be used to join the matched values.
|
||||||
separator = "."
|
separator = "."
|
||||||
|
|
||||||
### Default tags that will be added to all metrics. These can be overridden at the template level
|
|
||||||
### or by tags extracted from metric
|
|
||||||
tags = ["region=north-china", "zone=1c"]
|
|
||||||
|
|
||||||
### Each template line requires a template pattern. It can have an optional
|
### Each template line requires a template pattern. It can have an optional
|
||||||
### filter before the template and separated by spaces. It can also have optional extra
|
### filter before the template and separated by spaces. It can also have optional extra
|
||||||
### tags following the template. Multiple tags should be separated by commas and no spaces
|
### tags following the template. Multiple tags should be separated by commas and no spaces
|
||||||
### similar to the line protocol format. The can be only one default template.
|
### similar to the line protocol format. The can be only one default template.
|
||||||
### Templates support below format:
|
### Templates support below format:
|
||||||
### filter + template
|
### 1. filter + template
|
||||||
### filter + template + extra tag
|
### 2. filter + template + extra tag
|
||||||
### filter + template with field key
|
### 3. filter + template with field key
|
||||||
### default template. Ignore the first graphite component "servers"
|
### 4. default template
|
||||||
templates = [
|
templates = [
|
||||||
"*.app env.service.resource.measurement",
|
"*.app env.service.resource.measurement",
|
||||||
"stats.* .host.measurement* region=us-west,agent=sensu",
|
"stats.* .host.measurement* region=us-west,agent=sensu",
|
||||||
|
@ -110,9 +105,8 @@ func (s *Socket) Start() error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
c := NewConfig(s.BindAddress, s.Protocol, s.UdpReadBuffer, s.Separator, s.Tags, s.Templates)
|
c := NewConfig(s.BindAddress, s.Protocol, s.UdpReadBuffer, s.Separator, s.Templates)
|
||||||
|
|
||||||
c.WithDefaults()
|
|
||||||
if err := c.Validate(); err != nil {
|
if err := c.Validate(); err != nil {
|
||||||
return fmt.Errorf("Socket input configuration is error: %s ", err.Error())
|
return fmt.Errorf("Socket input configuration is error: %s ", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -120,7 +114,6 @@ func (s *Socket) Start() error {
|
||||||
|
|
||||||
graphiteParser, err := graphite.NewParserWithOptions(graphite.Options{
|
graphiteParser, err := graphite.NewParserWithOptions(graphite.Options{
|
||||||
Templates: s.config.Templates,
|
Templates: s.config.Templates,
|
||||||
DefaultTags: s.config.DefaultTags(),
|
|
||||||
Separator: s.config.Separator})
|
Separator: s.config.Separator})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue