From ffe92a7658d31e99750bcf81e87b94e849ed9364 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Tue, 30 Mar 2021 01:05:19 +0200 Subject: [PATCH] Don't walk the entire interface table to just retrieve one field (#9043) --- plugins/processors/ifname/ifname.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/processors/ifname/ifname.go b/plugins/processors/ifname/ifname.go index 10cf38a3cec8a..52a9161b0f6fe 100644 --- a/plugins/processors/ifname/ifname.go +++ b/plugins/processors/ifname/ifname.go @@ -201,13 +201,13 @@ func (d *IfName) Start(acc telegraf.Accumulator) error { return fmt.Errorf("parsing SNMP client config: %w", err) } - d.ifTable, err = d.makeTable("IF-MIB::ifTable") + d.ifTable, err = d.makeTable("IF-MIB::ifDescr") if err != nil { - return fmt.Errorf("looking up ifTable in local MIB: %w", err) + return fmt.Errorf("looking up ifDescr in local MIB: %w", err) } - d.ifXTable, err = d.makeTable("IF-MIB::ifXTable") + d.ifXTable, err = d.makeTable("IF-MIB::ifName") if err != nil { - return fmt.Errorf("looking up ifXTable in local MIB: %w", err) + return fmt.Errorf("looking up ifName in local MIB: %w", err) } fn := func(m telegraf.Metric) []telegraf.Metric { @@ -347,11 +347,13 @@ func init() { }) } -func makeTableNoMock(tableName string) (*si.Table, error) { +func makeTableNoMock(fieldName string) (*si.Table, error) { var err error tab := si.Table{ - Oid: tableName, IndexAsTag: true, + Fields: []si.Field{ + {Oid: fieldName}, + }, } err = tab.Init()