"os/exec"
"strconv"
"strings"
+ "sync"
"time"
"github.com/dustin/go-humanize"
Swap string = ""
Flags string = "?"
IOs string = "?"
- Net string = "?"
+ Net = map[string]string{}
+ NetM sync.RWMutex
)
func piper(c chan []string, name string, args ...string) error {
}
}
-func netstat() {
- for cols := range bg("netstat", "-I", "bridge0", "-n", "1") {
+func netstat(iface string) {
+ for cols := range bg("netstat", "-I", iface, "-n", "1") {
if _, err := strconv.Atoi(cols[0]); err != nil {
continue
}
if err != nil {
continue
}
- Net = fmt.Sprintf(
- "%s/%s %s / %s",
- cols[0], cols[4],
+ _ = cols[0] // pkts rx
+ _ = cols[4] // pkts tx
+ NetM.Lock()
+ Net[iface] = fmt.Sprintf(
+ "%s:%s/%s",
+ iface,
humanize.IBytes(uint64(ibps)),
humanize.IBytes(uint64(obps)),
)
+ NetM.Unlock()
}
}
go top()
go freq()
go iostat()
- go netstat()
+ go netstat("bridge0")
+ go netstat("ix0")
var now time.Time
var status string
var cmd *exec.Cmd
for {
now = time.Now()
+ NetM.RLock()
status = fmt.Sprintf(
- "[%s] [%s] [%s %s] [%s%s %s ARC] [%s] %s",
- IOs, Net, CPU, Freq, Swap, Mem, ARC, Flags,
+ "[%s] [%s %s] [%s %s] [%s%s %s ARC] [%s] %s",
+ IOs, Net["bridge0"], Net["ix0"], CPU, Freq, Swap, Mem, ARC, Flags,
now.Format("2006-01-02 15:04:05"),
)
+ NetM.RUnlock()
if *xsetroot {
cmd = exec.Command("xsetroot", "-name", status)
cmd.Run()