make single network interface about NetIOCounters on darwin and freebsd
This commit is contained in:
parent
406cbe9b87
commit
3ff690d1d8
|
@ -6,6 +6,8 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
|
@ -16,6 +18,7 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
|
|
||||||
lines := strings.Split(string(out), "\n")
|
lines := strings.Split(string(out), "\n")
|
||||||
ret := make([]NetIOCountersStat, 0, len(lines)-1)
|
ret := make([]NetIOCountersStat, 0, len(lines)-1)
|
||||||
|
exists := make([]string, 0, len(ret))
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
values := strings.Fields(line)
|
values := strings.Fields(line)
|
||||||
|
@ -23,6 +26,12 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
// skip first line
|
// skip first line
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if common.StringContains(exists, values[0]) {
|
||||||
|
// skip if already get
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
exists = append(exists, values[0])
|
||||||
|
|
||||||
base := 1
|
base := 1
|
||||||
// sometimes Address is ommitted
|
// sometimes Address is ommitted
|
||||||
if len(values) < 11 {
|
if len(values) < 11 {
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
|
@ -16,12 +18,19 @@ func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
|
|
||||||
lines := strings.Split(string(out), "\n")
|
lines := strings.Split(string(out), "\n")
|
||||||
ret := make([]NetIOCountersStat, 0, len(lines)-1)
|
ret := make([]NetIOCountersStat, 0, len(lines)-1)
|
||||||
|
exists := make([]string, 0, len(ret))
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
values := strings.Fields(line)
|
values := strings.Fields(line)
|
||||||
if len(values) < 1 || values[0] == "Name" {
|
if len(values) < 1 || values[0] == "Name" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if common.StringContains(exists, values[0]) {
|
||||||
|
// skip if already get
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
exists = append(exists, values[0])
|
||||||
|
|
||||||
base := 1
|
base := 1
|
||||||
// sometimes Address is ommitted
|
// sometimes Address is ommitted
|
||||||
if len(values) < 13 {
|
if len(values) < 13 {
|
||||||
|
|
Loading…
Reference in New Issue