Skip to content

Commit

Permalink
cmd/scollector: WIP Monitoring teams interfaces
Browse files Browse the repository at this point in the history
Currently we monitor bonding which works with CentOS 6, but by default CentOS 7 is using teaming and we want to monitor that as well.
  • Loading branch information
kylebrandt committed Aug 26, 2015
1 parent 8e9c0a5 commit c9fc584
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions cmd/scollector/collectors/ifstat_linux.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package collectors

import (
"encoding/json"
"io/ioutil"
"log"
"os"
"regexp"
"strings"
"time"

"bosun.org/metadata"
"bosun.org/opentsdb"
Expand All @@ -12,6 +17,7 @@ import (
func init() {
collectors = append(collectors, &IntervalCollector{F: c_ifstat_linux})
collectors = append(collectors, &IntervalCollector{F: c_ipcount_linux})
collectors = append(collectors, &IntervalCollector{F: c_if_team_linux})
}

var netFields = []struct {
Expand Down Expand Up @@ -106,3 +112,119 @@ func c_ifstat_linux() (opentsdb.MultiDataPoint, error) {
})
return md, err
}

func c_if_team_linux() (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
getState := func(iname string) (TeamState, error) {
var ts TeamState
reader, err := util.Command(time.Second*5, nil, "teamdctl", iname, "state", "dump")
if err != nil {
return ts, err
}
err = json.NewDecoder(reader).Decode(&ts)
if err != nil {
return ts, err
}
return ts, nil
}
if _, err := os.Stat("/sys/module/team"); os.IsNotExist(err) {
return md, nil
}
virtInterfaces, err := ioutil.ReadDir("/sys/devices/virtual/net")
if err != nil {
return md, nil
}
for _, f := range virtInterfaces {
name := f.Name()
if strings.HasPrefix(name, "team") {
ts, err := getState(name)
if err != nil {
return md, err
}
for portName, port := range ts.TeamPorts {
// Do the things
log.Println(portName, port)
}
}
}
return md, nil
}

type TeamState struct {
TeamPorts map[string]TeamPort `json:"ports"`
Runner struct {
Active bool `json:"active"`
FastRate bool `json:"fast_rate"`
SelectPolicy string `json:"select_policy"`
SysPrio float64 `json:"sys_prio"`
} `json:"runner"`
Setup struct {
Daemonized bool `json:"daemonized"`
DbusEnabled bool `json:"dbus_enabled"`
DebugLevel float64 `json:"debug_level"`
KernelTeamModeName string `json:"kernel_team_mode_name"`
Pid float64 `json:"pid"`
PidFile string `json:"pid_file"`
RunnerName string `json:"runner_name"`
ZmqEnabled bool `json:"zmq_enabled"`
} `json:"setup"`
TeamDevice struct {
Ifinfo struct {
DevAddr string `json:"dev_addr"`
DevAddrLen float64 `json:"dev_addr_len"`
Ifindex float64 `json:"ifindex"`
Ifname string `json:"ifname"`
} `json:"ifinfo"`
} `json:"team_device"`
}

type TeamPort struct {
Ifinfo struct {
DevAddr string `json:"dev_addr"`
DevAddrLen float64 `json:"dev_addr_len"`
Ifindex float64 `json:"ifindex"`
Ifname string `json:"ifname"`
}
Link struct {
Duplex string `json:"duplex"`
Speed float64 `json:"speed"`
Up bool `json:"up"`
} `json:"link"`
LinkWatches struct {
List struct {
LinkWatch0 struct {
DelayDown float64 `json:"delay_down"`
DelayUp float64 `json:"delay_up"`
Name string `json:"name"`
Up bool `json:"up"`
} `json:"link_watch_0"`
} `json:"list"`
Up bool `json:"up"`
} `json:"link_watches"`
Runner struct {
ActorLacpduInfo struct {
Key float64 `json:"key"`
Port float64 `json:"port"`
PortPriority float64 `json:"port_priority"`
State float64 `json:"state"`
System string `json:"system"`
SystemPriority float64 `json:"system_priority"`
} `json:"actor_lacpdu_info"`
Aggregator struct {
ID float64 `json:"id"`
Selected bool `json:"selected"`
} `json:"aggregator"`
Key float64 `json:"key"`
PartnerLacpduInfo struct {
Key float64 `json:"key"`
Port float64 `json:"port"`
PortPriority float64 `json:"port_priority"`
State float64 `json:"state"`
System string `json:"system"`
SystemPriority float64 `json:"system_priority"`
} `json:"partner_lacpdu_info"`
Prio float64 `json:"prio"`
Selected bool `json:"selected"`
State string `json:"state"`
} `json:"runner"`
}

0 comments on commit c9fc584

Please sign in to comment.