Skip to content

Commit

Permalink
Support strings in statsd set measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc authored and Nick White committed Jan 31, 2017
1 parent bdb7b85 commit 65ebd1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ plugins, not just statsd.
- [#1913](https://github.com/influxdata/telegraf/pull/1913): OpenTSDB basic auth support.
- [#1908](https://github.com/influxdata/telegraf/pull/1908): RabbitMQ Connection metrics.
- [#1937](https://github.com/influxdata/telegraf/pull/1937): HAProxy session limit metric.
- [#2068](https://github.com/influxdata/telegraf/issues/2068): Accept strings for StatsD sets.

### Bugfixes

Expand Down
13 changes: 8 additions & 5 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type metric struct {
hash string
intvalue int64
floatvalue float64
strvalue string
mtype string
additive bool
samplerate float64
Expand All @@ -106,7 +107,7 @@ type metric struct {

type cachedset struct {
name string
fields map[string]map[int64]bool
fields map[string]map[string]bool
tags map[string]string
}

Expand Down Expand Up @@ -435,7 +436,7 @@ func (s *Statsd) parseStatsdLine(line string) error {
return errors.New("Error Parsing statsd line")
}
m.floatvalue = v
case "c", "s":
case "c":
var v int64
v, err := strconv.ParseInt(pipesplit[0], 10, 64)
if err != nil {
Expand All @@ -451,6 +452,8 @@ func (s *Statsd) parseStatsdLine(line string) error {
v = int64(float64(v) / m.samplerate)
}
m.intvalue = v
case "s":
m.strvalue = pipesplit[0]
}

// Parse the name & tags from bucket
Expand Down Expand Up @@ -625,16 +628,16 @@ func (s *Statsd) aggregate(m metric) {
if !ok {
s.sets[m.hash] = cachedset{
name: m.name,
fields: make(map[string]map[int64]bool),
fields: make(map[string]map[string]bool),
tags: m.tags,
}
}
// check if the field exists
_, ok = s.sets[m.hash].fields[m.field]
if !ok {
s.sets[m.hash].fields[m.field] = make(map[int64]bool)
s.sets[m.hash].fields[m.field] = make(map[string]bool)
}
s.sets[m.hash].fields[m.field][m.intvalue] = true
s.sets[m.hash].fields[m.field][m.strvalue] = true
}
}

Expand Down
7 changes: 7 additions & 0 deletions plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func TestParse_Sets(t *testing.T) {
"scientific.notation.sets:4.696E+5|s",
"scientific.notation.sets:4.696E+5|s",
"scientific.notation.sets:4.697E+5|s",
"string.sets:foobar|s",
"string.sets:foobar|s",
"string.sets:bar|s",
}

for _, line := range valid_lines {
Expand All @@ -164,6 +167,10 @@ func TestParse_Sets(t *testing.T) {
"oneuser_id",
1,
},
{
"string_sets",
2,
},
}

for _, test := range validations {
Expand Down

0 comments on commit 65ebd1f

Please sign in to comment.