|
@@ -111,6 +111,37 @@ func GetNetworkInterfaceStats() (int64, int64, error) {
|
|
|
|
|
|
//Return value as bits
|
|
|
return rxSum * 8, txSum * 8, nil
|
|
|
+
|
|
|
+ } else if runtime.GOOS == "darwin" {
|
|
|
+ cmd := exec.Command("netstat", "-ib") //get data from netstat -ib
|
|
|
+ out, err := cmd.Output()
|
|
|
+ if err != nil {
|
|
|
+ return 0, 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ outStrs := string(out[:]) //byte array to multi-line string
|
|
|
+ for _, outStr := range strings.Split(strings.TrimSuffix(outStrs, "\n"), "\n") { //foreach multi-line string
|
|
|
+ if strings.HasPrefix(outStr, "en") { //search for ethernet interface
|
|
|
+ if strings.Contains(outStr, "<Link#") { //search for the link with <Link#?>
|
|
|
+ outStrSplit := strings.Fields(outStr) //split by white-space
|
|
|
+
|
|
|
+ rxSum, errRX := strconv.Atoi(outStrSplit[6]) //received bytes sum
|
|
|
+ if errRX != nil {
|
|
|
+ return 0, 0, errRX
|
|
|
+ }
|
|
|
+
|
|
|
+ txSum, errTX := strconv.Atoi(outStrSplit[9]) //transmitted bytes sum
|
|
|
+ if errTX != nil {
|
|
|
+ return 0, 0, errTX
|
|
|
+ }
|
|
|
+
|
|
|
+ return int64(rxSum), int64(txSum), nil //return results
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ outStrs = ""
|
|
|
+
|
|
|
+ return 0, 0, nil //no ethernet adapters with en*/<Link#*>
|
|
|
}
|
|
|
|
|
|
return 0, 0, errors.New("Platform not supported")
|