Skip to content

Commit

Permalink
Add option to disable statsd name conversion
Browse files Browse the repository at this point in the history
closes #467
closes #532
  • Loading branch information
sparrc committed Jan 15, 2016
1 parent 40a5bad commit c483e16
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
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

0 comments on commit c483e16

Please sign in to comment.