Use a single measurement with fields for timings in statsd plugin.

This commit is contained in:
Marcin Bunsch 2016-01-28 14:49:28 +01:00
parent c549ab907a
commit 57908cd114
2 changed files with 19 additions and 40 deletions

View File

@ -162,15 +162,17 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
defer s.Unlock() defer s.Unlock()
for _, metric := range s.timings { for _, metric := range s.timings {
acc.Add(metric.name+"_mean", metric.stats.Mean(), metric.tags) fields := make(map[string]interface{})
acc.Add(metric.name+"_stddev", metric.stats.Stddev(), metric.tags) fields["mean"] = metric.stats.Mean()
acc.Add(metric.name+"_upper", metric.stats.Upper(), metric.tags) fields["stddev"] = metric.stats.Stddev()
acc.Add(metric.name+"_lower", metric.stats.Lower(), metric.tags) fields["upper"] = metric.stats.Upper()
acc.Add(metric.name+"_count", metric.stats.Count(), metric.tags) fields["lower"] = metric.stats.Lower()
fields["count"] = metric.stats.Count()
for _, percentile := range s.Percentiles { for _, percentile := range s.Percentiles {
name := fmt.Sprintf("%s_percentile_%v", metric.name, percentile) name := fmt.Sprintf("%v_percentile", percentile)
acc.Add(name, metric.stats.Percentile(percentile), metric.tags) fields[name] = metric.stats.Percentile(percentile)
} }
acc.AddFields(metric.name, fields, metric.tags)
} }
if s.DeleteTimings { if s.DeleteTimings {
s.timings = make(map[string]cachedtimings) s.timings = make(map[string]cachedtimings)

View File

@ -710,7 +710,7 @@ func TestParse_Timings(t *testing.T) {
// Test that counters work // Test that counters work
valid_lines := []string{ valid_lines := []string{
"test.timing:1|ms", "test.timing:1|ms",
"test.timing:1|ms", "test.timing:11|ms",
"test.timing:1|ms", "test.timing:1|ms",
"test.timing:1|ms", "test.timing:1|ms",
"test.timing:1|ms", "test.timing:1|ms",
@ -725,40 +725,17 @@ func TestParse_Timings(t *testing.T) {
s.Gather(acc) s.Gather(acc)
tests := []struct { valid := map[string]interface{} {
name string "90_percentile": float64(11),
value interface{} "count": int64(5),
}{ "lower": float64(1),
{ "mean": float64(3),
"test_timing_mean", "stddev": float64(4),
float64(1), "upper": float64(11),
},
{
"test_timing_stddev",
float64(0),
},
{
"test_timing_upper",
float64(1),
},
{
"test_timing_lower",
float64(1),
},
{
"test_timing_count",
int64(5),
},
{
"test_timing_percentile_90",
float64(1),
},
} }
for _, test := range tests { acc.AssertContainsFields(t, "test_timing", valid)
acc.AssertContainsFields(t, test.name,
map[string]interface{}{"value": test.value})
}
} }
func TestParse_Timings_Delete(t *testing.T) { func TestParse_Timings_Delete(t *testing.T) {