Add option to disable statsd name conversion

closes #467
closes #532
This commit is contained in:
Cameron Sparr 2016-01-15 15:38:32 -07:00
parent 40a5bad968
commit c483e16d72
3 changed files with 70 additions and 3 deletions

View File

@ -5,6 +5,7 @@
- [#512](https://github.com/influxdata/telegraf/pull/512): Python 3 build script, add lsof dep to package. Thanks @Ormod! - [#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! - [#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! - [#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 ### Bugfixes
- [#506](https://github.com/influxdb/telegraf/pull/506): Ping input doesn't return response time metric when timeout. Thanks @titilambert! - [#506](https://github.com/influxdb/telegraf/pull/506): Ping input doesn't return response time metric when timeout. Thanks @titilambert!

View File

@ -35,6 +35,7 @@ type Statsd struct {
DeleteCounters bool DeleteCounters bool
DeleteSets bool DeleteSets bool
DeleteTimings bool DeleteTimings bool
ConvertNames bool
sync.Mutex sync.Mutex
@ -63,6 +64,8 @@ func NewStatsd() *Statsd {
s.sets = make(map[string]cachedset) s.sets = make(map[string]cachedset)
s.timings = make(map[string]cachedtimings) s.timings = make(map[string]cachedtimings)
s.ConvertNames = true
return &s return &s
} }
@ -121,6 +124,9 @@ const sampleConfig = `
# Percentiles to calculate for timing & histogram stats # Percentiles to calculate for timing & histogram stats
percentiles = [90] percentiles = [90]
# convert measurement names, "." to "_" and "-" to "__"
convert_names = true
# templates = [ # templates = [
# "cpu.* measurement*" # "cpu.* measurement*"
# ] # ]
@ -389,8 +395,10 @@ func (s *Statsd) parseName(bucket string) (string, map[string]string) {
if err == nil { if err == nil {
name, tags, _, _ = p.ApplyTemplate(name) name, tags, _, _ = p.ApplyTemplate(name)
} }
if s.ConvertNames {
name = strings.Replace(name, ".", "_", -1) name = strings.Replace(name, ".", "_", -1)
name = strings.Replace(name, "-", "__", -1) name = strings.Replace(name, "-", "__", -1)
}
return name, tags return name, tags
} }
@ -491,6 +499,6 @@ func (s *Statsd) Stop() {
func init() { func init() {
inputs.Add("statsd", func() inputs.Input { inputs.Add("statsd", func() inputs.Input {
return &Statsd{} return &Statsd{ConvertNames: true}
}) })
} }

View File

@ -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 // Test that measurements with the same name, but different tags, are treated
// as different outputs // as different outputs
func TestParse_MeasurementsWithSameName(t *testing.T) { func TestParse_MeasurementsWithSameName(t *testing.T) {