Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging poll interval for snmp #708

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/inputs/snmp/metadata/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metadata

import (
"context"
"fmt"
"regexp"
"strconv"
"strings"
Expand All @@ -12,6 +13,7 @@ import (

"github.com/kentik/ktranslate/pkg/eggs/logger"
"github.com/kentik/ktranslate/pkg/inputs/snmp/mibs"
"github.com/kentik/ktranslate/pkg/inputs/snmp/util"
"github.com/kentik/ktranslate/pkg/kt"
"github.com/kentik/ktranslate/pkg/util/tick"
)
Expand All @@ -29,6 +31,7 @@ type Poller struct {
deviceMetadataMibs map[string]*kt.Mib
interfaceMetadataMibs map[string]*kt.Mib
matchAttr map[string]*regexp.Regexp
counterTimeSec string
}

const (
Expand Down Expand Up @@ -87,6 +90,8 @@ func NewPoller(server *gosnmp.GoSNMP, gconf *kt.SnmpGlobalConfig, conf *kt.SnmpD
log.Infof("Added %d Match Attribute(s)", len(attrMap))
}

counterTimeSec := util.GetPollRate(gconf, conf, log)

return &Poller{
gconf: gconf,
conf: conf,
Expand All @@ -100,6 +105,7 @@ func NewPoller(server *gosnmp.GoSNMP, gconf *kt.SnmpGlobalConfig, conf *kt.SnmpD
deviceMetadataMibs: deviceMetadataMibs,
interfaceMetadataMibs: interfaceMetadataMibs,
matchAttr: attrMap,
counterTimeSec: fmt.Sprintf("%v", time.Duration(counterTimeSec)*time.Second),
}
}

Expand Down Expand Up @@ -256,7 +262,8 @@ func (p *Poller) toFlows(dd *kt.DeviceData) ([]*kt.JCHF, error) {

// Also any device level tags
cs := map[string]string{ // Set log level as a SysLogLevel key here so that Uptime metrics get it only.
"SysLogLevel": p.log.GetLogger().GetUnderlyingLogger().GetLogLevel(),
"SysLogLevel": p.log.GetLogger().GetUnderlyingLogger().GetLogLevel(),
"SysPollInterval": p.counterTimeSec,
}
p.conf.SetUserTags(cs)
for k, v := range cs {
Expand Down
40 changes: 4 additions & 36 deletions pkg/inputs/snmp/metrics/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/kentik/ktranslate/pkg/eggs/logger"
"github.com/kentik/ktranslate/pkg/inputs/snmp/mibs"
"github.com/kentik/ktranslate/pkg/inputs/snmp/ping"
"github.com/kentik/ktranslate/pkg/inputs/snmp/util"
extension "github.com/kentik/ktranslate/pkg/inputs/snmp/x"
"github.com/kentik/ktranslate/pkg/kt"
"github.com/kentik/ktranslate/pkg/util/tick"
Expand All @@ -35,18 +36,7 @@ type Poller struct {
}

func NewPoller(server *gosnmp.GoSNMP, gconf *kt.SnmpGlobalConfig, conf *kt.SnmpDeviceConfig, jchfChan chan []*kt.JCHF, metrics *kt.SnmpDeviceMetric, profile *mibs.Profile, log logger.ContextL, logchan chan string) *Poller {
// Default poll rate is 5 min. This is what a lot of SNMP billing is on.
counterTimeSec := 5 * 60
if conf != nil && conf.PollTimeSec > 0 {
counterTimeSec = conf.PollTimeSec
} else if gconf != nil && gconf.PollTimeSec > 0 {
counterTimeSec = gconf.PollTimeSec
}
// Lastly, enforece a min polling interval.
if counterTimeSec < 30 {
log.Warnf("%d poll time is below min of 30. Raising to 30 seconds", counterTimeSec)
counterTimeSec = 30
}
counterTimeSec := util.GetPollRate(gconf, conf, log)

jitterTimeSec := 15 // This is how long to spead the polling load out across.
if gconf.JitterTimeSec > 0 {
Expand Down Expand Up @@ -96,18 +86,7 @@ func NewPoller(server *gosnmp.GoSNMP, gconf *kt.SnmpGlobalConfig, conf *kt.SnmpD
}

func NewPollerForPing(gconf *kt.SnmpGlobalConfig, conf *kt.SnmpDeviceConfig, jchfChan chan []*kt.JCHF, metrics *kt.SnmpDeviceMetric, profile *mibs.Profile, log logger.ContextL) *Poller {
// Default poll rate is 5 min. This is what a lot of SNMP billing is on.
counterTimeSec := 5 * 60
if conf != nil && conf.PollTimeSec > 0 {
counterTimeSec = conf.PollTimeSec
} else if gconf != nil && gconf.PollTimeSec > 0 {
counterTimeSec = gconf.PollTimeSec
}
// Lastly, enforece a min polling interval.
if counterTimeSec < 30 {
log.Warnf("%d poll time is below min of 30. Raising to 30 seconds", counterTimeSec)
counterTimeSec = 30
}
counterTimeSec := util.GetPollRate(gconf, conf, log)

jitterTimeSec := 15 // This is how long to spead the polling load out across.
if gconf.JitterTimeSec > 0 {
Expand Down Expand Up @@ -145,18 +124,7 @@ func NewPollerForPing(gconf *kt.SnmpGlobalConfig, conf *kt.SnmpDeviceConfig, jch
}

func NewPollerForExtention(gconf *kt.SnmpGlobalConfig, conf *kt.SnmpDeviceConfig, jchfChan chan []*kt.JCHF, metrics *kt.SnmpDeviceMetric, profile *mibs.Profile, log logger.ContextL, logchan chan string) *Poller {
// Default poll rate is 5 min. This is what a lot of SNMP billing is on.
counterTimeSec := 5 * 60
if conf != nil && conf.PollTimeSec > 0 {
counterTimeSec = conf.PollTimeSec
} else if gconf != nil && gconf.PollTimeSec > 0 {
counterTimeSec = gconf.PollTimeSec
}
// Lastly, enforece a min polling interval.
if counterTimeSec < 30 {
log.Warnf("%d poll time is below min of 30. Raising to 30 seconds", counterTimeSec)
counterTimeSec = 30
}
counterTimeSec := util.GetPollRate(gconf, conf, log)

jitterTimeSec := 15 // This is how long to spead the polling load out across.
if gconf.JitterTimeSec > 0 {
Expand Down
17 changes: 17 additions & 0 deletions pkg/inputs/snmp/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ func DoWalk(device string, baseOid string, format string, conf *kt.SnmpConfig, c
return fmt.Errorf("ok")
}

func GetPollRate(gconf *kt.SnmpGlobalConfig, conf *kt.SnmpDeviceConfig, log logger.ContextL) int {
// Default poll rate is 5 min. This is what a lot of SNMP billing is on.
counterTimeSec := 5 * 60
if conf != nil && conf.PollTimeSec > 0 {
counterTimeSec = conf.PollTimeSec
} else if gconf != nil && gconf.PollTimeSec > 0 {
counterTimeSec = gconf.PollTimeSec
}
// Lastly, enforece a min polling interval.
if counterTimeSec < 30 {
log.Warnf("%d poll time is below min of 30. Raising to 30 seconds", counterTimeSec)
counterTimeSec = 30
}

return counterTimeSec
}

// Handle the case of wierd ints encoded as byte arrays.
func GetFromConv(pdu gosnmp.SnmpPDU, conv string, log logger.ContextL) (int64, string, map[string]string) {
defer func() {
Expand Down
Loading