make single network interface about NetIOCounters on darwin and freebsd

This commit is contained in:
Shirou WAKAYAMA 2015-01-01 21:54:45 +09:00
parent 406cbe9b87
commit 3ff690d1d8
2 changed files with 18 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import (
"os/exec"
"strconv"
"strings"
"github.com/shirou/gopsutil/common"
)
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
@ -16,6 +18,7 @@ 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)
@ -23,6 +26,12 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
// 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 {

View File

@ -6,6 +6,8 @@ import (
"os/exec"
"strconv"
"strings"
"github.com/shirou/gopsutil/common"
)
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
@ -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 {