Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable statsd name conversion #532

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [#512](https://github.com/influxdata/telegraf/pull/512): Python 3 build script, add lsof dep to package. Thanks @Ormod!
- [#475](https://github.com/influxdata/telegraf/pull/475): Add response time to httpjson plugin. Thanks @titilambert!
- [#519](https://github.com/influxdata/telegraf/pull/519): Added a sensors input based on lm-sensors. Thanks @md14454!
- [#467](https://github.com/influxdata/telegraf/issues/467): Add option to disable statsd measurement name conversion.

### Bugfixes
- [#506](https://github.com/influxdb/telegraf/pull/506): Ping input doesn't return response time metric when timeout. Thanks @titilambert!
Expand Down
14 changes: 11 additions & 3 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Statsd struct {
DeleteCounters bool
DeleteSets bool
DeleteTimings bool
ConvertNames bool

sync.Mutex

Expand Down Expand Up @@ -63,6 +64,8 @@ func NewStatsd() *Statsd {
s.sets = make(map[string]cachedset)
s.timings = make(map[string]cachedtimings)

s.ConvertNames = true

return &s
}

Expand Down Expand Up @@ -121,6 +124,9 @@ const sampleConfig = `
# Percentiles to calculate for timing & histogram stats
percentiles = [90]

# convert measurement names, "." to "_" and "-" to "__"
convert_names = true

# templates = [
# "cpu.* measurement*"
# ]
Expand Down Expand Up @@ -389,8 +395,10 @@ func (s *Statsd) parseName(bucket string) (string, map[string]string) {
if err == nil {
name, tags, _, _ = p.ApplyTemplate(name)
}
name = strings.Replace(name, ".", "_", -1)
name = strings.Replace(name, "-", "__", -1)
if s.ConvertNames {
name = strings.Replace(name, ".", "_", -1)
name = strings.Replace(name, "-", "__", -1)
}

return name, tags
}
Expand Down Expand Up @@ -491,6 +499,6 @@ func (s *Statsd) Stop() {

func init() {
inputs.Add("statsd", func() inputs.Input {
return &Statsd{}
return &Statsd{ConvertNames: true}
})
}
58 changes: 58 additions & 0 deletions plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,64 @@ func TestParse_Tags(t *testing.T) {
}
}

// Test that statsd buckets are parsed to measurement names properly
func TestParseName(t *testing.T) {
s := NewStatsd()

tests := []struct {
in_name string
out_name string
}{
{
"foobar",
"foobar",
},
{
"foo.bar",
"foo_bar",
},
{
"foo.bar-baz",
"foo_bar__baz",
},
}

for _, test := range tests {
name, _ := s.parseName(test.in_name)
if name != test.out_name {
t.Errorf("Expected: %s, got %s", test.out_name, name)
}
}

// Test with ConvertNames = false
s.ConvertNames = false

tests = []struct {
in_name string
out_name string
}{
{
"foobar",
"foobar",
},
{
"foo.bar",
"foo.bar",
},
{
"foo.bar-baz",
"foo.bar-baz",
},
}

for _, test := range tests {
name, _ := s.parseName(test.in_name)
if name != test.out_name {
t.Errorf("Expected: %s, got %s", test.out_name, name)
}
}
}

// Test that measurements with the same name, but different tags, are treated
// as different outputs
func TestParse_MeasurementsWithSameName(t *testing.T) {
Expand Down