Skip to content

Commit

Permalink
cmd/scollector: Update SNMP timeout from 5s to 30s and allow override (
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrayut authored Sep 13, 2016
1 parent 63eba65 commit b8c80c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/scollector/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type Conf struct {
// UserAgentMessage is an optional message that is appended to the User Agent
UserAgentMessage string

// SNMPTimeout is the number of seconds to wait for SNMP responses (default 30)
SNMPTimeout int

HAProxy []HAProxy
SNMP []SNMP
MIBS map[string]MIB
Expand Down
4 changes: 4 additions & 0 deletions cmd/scollector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"bosun.org/metadata"
"bosun.org/opentsdb"
"bosun.org/slog"
"bosun.org/snmp"
"bosun.org/util"
"github.com/BurntSushi/toml"
"github.com/facebookgo/httpcontrol"
Expand Down Expand Up @@ -123,6 +124,9 @@ func main() {
if conf.ColDir != "" {
collectors.InitPrograms(conf.ColDir)
}
if conf.SNMPTimeout > 0 {
snmp.Timeout = conf.SNMPTimeout
}
var err error
check := func(e error) {
if e != nil {
Expand Down
5 changes: 4 additions & 1 deletion snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"bosun.org/snmp/asn1"
)

//Timeout is the number of seconds to use for conn.SetReadDeadline
var Timeout = 30

// reserved binding values.
var (
null = asn1.RawValue{Class: 0, Tag: 5}
Expand Down Expand Up @@ -236,7 +239,7 @@ func (s *SNMP) do(req *request) (*response, error) {
return nil, err
}
buf = make([]byte, 10000, 10000)
if err := conn.SetReadDeadline(time.Now().Add(5 * time.Second)); err != nil {
if err := conn.SetReadDeadline(time.Now().Add(time.Duration(Timeout) * time.Second)); err != nil {
return nil, err
}
n, err := conn.Read(buf)
Expand Down

0 comments on commit b8c80c1

Please sign in to comment.