Skip to content

Commit

Permalink
make single network interface about NetIOCounters on darwin and freebsd
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Jan 1, 2015
1 parent 406cbe9 commit 3ff690d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions net/net_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os/exec"
"strconv"
"strings"

"github.com/shirou/gopsutil/common"
)

func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
Expand All @@ -16,13 +18,20 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {

lines := strings.Split(string(out), "\n")
ret := make([]NetIOCountersStat, 0, len(lines)-1)
exists := make([]string, 0, len(ret))

for _, line := range lines {
values := strings.Fields(line)
if len(values) < 1 || values[0] == "Name" {
// skip first line
continue
}
if common.StringContains(exists, values[0]) {
// skip if already get
continue
}
exists = append(exists, values[0])

base := 1
// sometimes Address is ommitted
if len(values) < 11 {
Expand Down
9 changes: 9 additions & 0 deletions net/net_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os/exec"
"strconv"
"strings"

"github.com/shirou/gopsutil/common"
)

func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
Expand All @@ -16,12 +18,19 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {

lines := strings.Split(string(out), "\n")
ret := make([]NetIOCountersStat, 0, len(lines)-1)
exists := make([]string, 0, len(ret))

for _, line := range lines {
values := strings.Fields(line)
if len(values) < 1 || values[0] == "Name" {
continue
}
if common.StringContains(exists, values[0]) {
// skip if already get
continue
}
exists = append(exists, values[0])

base := 1
// sometimes Address is ommitted
if len(values) < 13 {
Expand Down

0 comments on commit 3ff690d

Please sign in to comment.