bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/snmp_lag.go (about)

     1  package collectors
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"bosun.org/cmd/scollector/conf"
     8  	"bosun.org/metadata"
     9  	"bosun.org/opentsdb"
    10  )
    11  
    12  const (
    13  	dot3adAggPortAttachedAggID = ".1.2.840.10006.300.43.1.2.1.1.13"
    14  )
    15  
    16  // SNMPLag registers a SNMP Interfaces collector for the given community and host.
    17  func SNMPLag(cfg conf.SNMP) {
    18  	collectors = append(collectors, &IntervalCollector{
    19  		F: func() (opentsdb.MultiDataPoint, error) {
    20  			return c_snmp_lag(cfg.Community, cfg.Host)
    21  		},
    22  		Interval: time.Second * 30,
    23  		name:     fmt.Sprintf("snmp-lag-%s", cfg.Host),
    24  	})
    25  }
    26  
    27  func c_snmp_lag(community, host string) (opentsdb.MultiDataPoint, error) {
    28  	ifNamesRaw, err := snmp_subtree(host, community, dot3adAggPortAttachedAggID)
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  	for k, v := range ifNamesRaw {
    33  		tags := opentsdb.TagSet{"host": host, "iface": k}
    34  		metadata.AddMeta("", tags, "masterIface", fmt.Sprintf("%v", v), false)
    35  	}
    36  	return nil, nil
    37  }