diff options
| -rw-r--r-- | fsbm.go | 53 |
1 files changed, 27 insertions, 26 deletions
@@ -1,12 +1,14 @@ package main -import "fmt" -import "bufio" -import "flag" -import "time" -import "os" -import "strings" -import "strconv" +import ( + "bufio" + "flag" + "fmt" + "os" + "strconv" + "strings" + "time" +) type Iface struct { Name string @@ -68,17 +70,16 @@ func main() { os.Exit(1) } - limitIfaces := false - requestedIfaces := make(map[string]struct{}) - if *interfaceFlag != "" { - for _, name := range strings.Split(*interfaceFlag, ",") { - requestedIfaces[name] = struct{}{} - } - if len(requestedIfaces) > 0 { - limitIfaces = true - } - } - + limitIfaces := false + requestedIfaces := make(map[string]struct{}) + if *interfaceFlag != "" { + for _, name := range strings.Split(*interfaceFlag, ",") { + requestedIfaces[name] = struct{}{} + } + if len(requestedIfaces) > 0 { + limitIfaces = true + } + } ifaces := make(map[string]Iface) var prevTime time.Time @@ -101,12 +102,12 @@ func main() { if !found { continue } - if limitIfaces { - _, ok := requestedIfaces[name]; - if !ok { - continue - } - } + if limitIfaces { + _, ok := requestedIfaces[name] + if !ok { + continue + } + } fields := strings.Fields(rest) if len(fields) != 16 { @@ -130,14 +131,14 @@ func main() { timeDiff := openTime.Sub(prevTime).Seconds() rxRate := float64(cur.RxBytes-prev.RxBytes) / timeDiff txRate := float64(cur.TxBytes-prev.TxBytes) / timeDiff - fmt.Printf("%s: (%s, %s) ", name, humanBps(rxRate, *rawFlag, *bitFlag), humanBps(txRate, *rawFlag, *bitFlag)) + fmt.Printf("%s: (%s, %s) ", name, humanBps(rxRate, *rawFlag, *bitFlag), humanBps(txRate, *rawFlag, *bitFlag)) } ifaces[name] = cur } - fmt.Printf("\n"); + fmt.Printf("\n") file.Close() prevTime = openTime time.Sleep(interval) |
