Skip to content

Commit

Permalink
Collect unbound histogram stats
Browse files Browse the repository at this point in the history
  • Loading branch information
zeloff committed Jan 29, 2025
1 parent 5b8dc15 commit d5551b6
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 14 deletions.
23 changes: 11 additions & 12 deletions plugins/inputs/unbound/unbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -47,12 +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 {
Expand All @@ -75,11 +68,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))
Expand All @@ -106,6 +94,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
Expand Down
84 changes: 82 additions & 2 deletions plugins/inputs/unbound/unbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d5551b6

Please sign in to comment.