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

cmd/scollector: Collect system uptime via snmp #1488

Merged
merged 1 commit into from
Dec 1, 2015
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 cmd/scollector/collectors/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ import (
"bosun.org/opentsdb"
)

var builtInSNMPs = map[string]func(cfg conf.SNMP){"ifaces": SNMPIfaces, "cisco": SNMPCisco, "bridge": SNMPBridge, "ips": SNMPIPAddresses, "ciscobgp": SNMPCiscoBGP}
var builtInSNMPs = map[string]func(cfg conf.SNMP){
"ifaces": SNMPIfaces,
"cisco": SNMPCisco,
"bridge": SNMPBridge,
"ips": SNMPIPAddresses,
"ciscobgp": SNMPCiscoBGP,
"sys": SNMPSys,
}

func SNMP(cfg conf.SNMP, mibs map[string]conf.MIB) error {
if cfg.Host == "" {
Expand Down
34 changes: 34 additions & 0 deletions cmd/scollector/collectors/snmp_sys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package collectors

import (
"fmt"
"math/big"
"time"

"bosun.org/cmd/scollector/conf"
"bosun.org/metadata"
"bosun.org/opentsdb"
)

const sysUpTime = ".1.3.6.1.2.1.1.3.0" // "The time (in hundredths of a second) since the network management portion of the system was last re-initialized."

// SNMPSys registers a SNMP system data collector for the given community and host.
func SNMPSys(cfg conf.SNMP) {
collectors = append(collectors, &IntervalCollector{
F: func() (opentsdb.MultiDataPoint, error) {
return c_snmp_sys(cfg.Community, cfg.Host)
},
Interval: time.Minute * 1,
name: fmt.Sprintf("snmp-sys-%s", cfg.Host),
})
}

func c_snmp_sys(community, host string) (opentsdb.MultiDataPoint, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably do this by building a hard-coded MIB struct like the cisco one does. I'm ok with this though. Do what feels good. LGTM

var md opentsdb.MultiDataPoint
uptime, err := snmp_oid(host, community, sysUpTime)
if err != nil {
return md, err
}
Add(&md, osSystemUptime, uptime.Int64()/big.NewInt(100).Int64(), opentsdb.TagSet{"host": host}, metadata.Gauge, metadata.Second, osSystemUptimeDesc)
return md, nil
}