diff --git a/plugins/inputs/unbound/unbound.go b/plugins/inputs/unbound/unbound.go index 9938a9a930f30..918f56f62675a 100644 --- a/plugins/inputs/unbound/unbound.go +++ b/plugins/inputs/unbound/unbound.go @@ -15,7 +15,6 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" - "github.com/influxdata/telegraf/filter" "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/plugins/inputs" ) @@ -47,13 +46,6 @@ func (*Unbound) SampleConfig() string { // All the dots in stat name will replaced by underscores. Histogram statistics will not be collected. func (s *Unbound) Gather(acc telegraf.Accumulator) error { - // Always exclude histogram statistics - statExcluded := []string{"histogram.*"} - filterExcluded, err := filter.Compile(statExcluded) - if err != nil { - return err - } - out, err := s.run(*s) if err != nil { return fmt.Errorf("error gathering metrics: %w", err) @@ -75,11 +67,6 @@ func (s *Unbound) Gather(acc telegraf.Accumulator) error { stat := cols[0] value := cols[1] - // Filter value - if filterExcluded.Match(stat) { - continue - } - fieldValue, err := strconv.ParseFloat(value, 64) if err != nil { acc.AddError(fmt.Errorf("expected a numerical value for %s = %v", stat, value)) @@ -106,6 +93,17 @@ func (s *Unbound) Gather(acc telegraf.Accumulator) error { fieldsThreads[threadID][field] = fieldValue } } + } else if strings.HasPrefix(stat, "histogram") { + statTokens := strings.Split(stat, ".") + if len(statTokens) > 1 { + lbound, err := strconv.ParseFloat(strings.Join(statTokens[1:3], "."), 64) + if err != nil { + acc.AddError(fmt.Errorf("expected a numeric value for the histogram bucket lower bound: %s", strings.Join(statTokens[1:3], "."))) + continue + } + field := fmt.Sprintf("%s_%f", statTokens[0], lbound) + fields[field] = fieldValue + } } else { field := strings.ReplaceAll(stat, ".", "_") fields[field] = fieldValue diff --git a/plugins/inputs/unbound/unbound_test.go b/plugins/inputs/unbound/unbound_test.go index c2011a01a3da6..f9cfc8c84a390 100644 --- a/plugins/inputs/unbound/unbound_test.go +++ b/plugins/inputs/unbound/unbound_test.go @@ -27,7 +27,7 @@ func TestParseFullOutput(t *testing.T) { require.True(t, acc.HasMeasurement("unbound")) require.Len(t, acc.Metrics, 1) - require.Equal(t, 63, acc.NFields()) + require.Equal(t, 103, acc.NFields()) acc.AssertContainsFields(t, "unbound", parsedFullOutput) } @@ -46,7 +46,7 @@ func TestParseFullOutputThreadAsTag(t *testing.T) { require.True(t, acc.HasMeasurement("unbound_threads")) require.Len(t, acc.Metrics, 2) - require.Equal(t, 63, acc.NFields()) + require.Equal(t, 103, acc.NFields()) acc.AssertContainsFields(t, "unbound", parsedFullOutputThreadAsTagMeasurementUnbound) acc.AssertContainsFields(t, "unbound_threads", parsedFullOutputThreadAsTagMeasurementUnboundThreads) @@ -87,6 +87,46 @@ var parsedFullOutput = map[string]interface{}{ "mem_cache_message": float64(320000), "mem_mod_iterator": float64(16532), "mem_mod_validator": float64(112097), + "histogram_0.000000": float64(20), + "histogram_0.000001": float64(5), + "histogram_0.000002": float64(13), + "histogram_0.000004": float64(18), + "histogram_0.000008": float64(67), + "histogram_0.000016": float64(94), + "histogram_0.000032": float64(113), + "histogram_0.000064": float64(190), + "histogram_0.000128": float64(369), + "histogram_0.000256": float64(1034), + "histogram_0.000512": float64(5503), + "histogram_0.001024": float64(155724), + "histogram_0.002048": float64(107623), + "histogram_0.004096": float64(17739), + "histogram_0.008192": float64(4177), + "histogram_0.016384": float64(82021), + "histogram_0.032768": float64(33772), + "histogram_0.065536": float64(7159), + "histogram_0.131072": float64(1109), + "histogram_0.262144": float64(295), + "histogram_0.524288": float64(890), + "histogram_1.000000": float64(136), + "histogram_1024.000000": float64(0), + "histogram_128.000000": float64(0), + "histogram_131072.000000": float64(0), + "histogram_16.000000": float64(2), + "histogram_16384.000000": float64(0), + "histogram_2.000000": float64(233), + "histogram_2048.000000": float64(0), + "histogram_256.000000": float64(0), + "histogram_262144.000000": float64(0), + "histogram_32.000000": float64(0), + "histogram_32768.000000": float64(0), + "histogram_4.000000": float64(2), + "histogram_4096.000000": float64(0), + "histogram_512.000000": float64(0), + "histogram_64.000000": float64(0), + "histogram_65536.000000": float64(0), + "histogram_8.000000": float64(0), + "histogram_8192.000000": float64(0), "num_query_type_A": float64(7062688), "num_query_type_PTR": float64(43097), "num_query_type_TXT": float64(2998), @@ -156,6 +196,46 @@ var parsedFullOutputThreadAsTagMeasurementUnbound = map[string]interface{}{ "mem_cache_message": float64(320000), "mem_mod_iterator": float64(16532), "mem_mod_validator": float64(112097), + "histogram_0.000000": float64(20), + "histogram_0.000001": float64(5), + "histogram_0.000002": float64(13), + "histogram_0.000004": float64(18), + "histogram_0.000008": float64(67), + "histogram_0.000016": float64(94), + "histogram_0.000032": float64(113), + "histogram_0.000064": float64(190), + "histogram_0.000128": float64(369), + "histogram_0.000256": float64(1034), + "histogram_0.000512": float64(5503), + "histogram_0.001024": float64(155724), + "histogram_0.002048": float64(107623), + "histogram_0.004096": float64(17739), + "histogram_0.008192": float64(4177), + "histogram_0.016384": float64(82021), + "histogram_0.032768": float64(33772), + "histogram_0.065536": float64(7159), + "histogram_0.131072": float64(1109), + "histogram_0.262144": float64(295), + "histogram_0.524288": float64(890), + "histogram_1.000000": float64(136), + "histogram_1024.000000": float64(0), + "histogram_128.000000": float64(0), + "histogram_131072.000000": float64(0), + "histogram_16.000000": float64(2), + "histogram_16384.000000": float64(0), + "histogram_2.000000": float64(233), + "histogram_2048.000000": float64(0), + "histogram_256.000000": float64(0), + "histogram_262144.000000": float64(0), + "histogram_32.000000": float64(0), + "histogram_32768.000000": float64(0), + "histogram_4.000000": float64(2), + "histogram_4096.000000": float64(0), + "histogram_512.000000": float64(0), + "histogram_64.000000": float64(0), + "histogram_65536.000000": float64(0), + "histogram_8.000000": float64(0), + "histogram_8192.000000": float64(0), "num_query_type_A": float64(7062688), "num_query_type_PTR": float64(43097), "num_query_type_TXT": float64(2998),