diff options
author | matt LLVW <matt.llvw@gmail.com> | 2019-05-14 18:09:17 +0200 |
---|---|---|
committer | matt LLVW <matt.llvw@gmail.com> | 2019-05-14 18:09:17 +0200 |
commit | 2be4549c15d91a652172fd12dabf63f495f0c87a (patch) | |
tree | f79f607c2d8181b221a29258089047838875ef75 | |
parent | 21cd6424249842c94b0abfaaa07080f6bad069c9 (diff) |
started
-rw-r--r-- | main.go | 5 | ||||
-rw-r--r-- | src/widgets/net.go | 14 |
2 files changed, 16 insertions, 3 deletions
@@ -47,6 +47,7 @@ var ( tempScale = w.Celcius battery = false statusbar = false + netInterface = "all" cpu *w.CpuWidget batt *w.BatteryWidget @@ -75,6 +76,7 @@ Options: -f, --fahrenheit Show temperatures in fahrenheit. -s, --statusbar Show a statusbar with the time. -b, --battery Show battery level widget ('minimal' turns off). + -i, --interface Select network interface [default: all]. Colorschemes: default @@ -116,6 +118,7 @@ Colorschemes: if fahrenheit { tempScale = w.Fahrenheit } + netInterface, _ := args["--interface"].(string) return nil } @@ -261,7 +264,7 @@ func initWidgets() { if battery { batt = w.NewBatteryWidget(graphHorizontalScale) } - net = w.NewNetWidget() + net = w.NewNetWidget(netInterface) disk = w.NewDiskWidget() temp = w.NewTempWidget(tempScale) } diff --git a/src/widgets/net.go b/src/widgets/net.go index 89def2a..b7a0532 100644 --- a/src/widgets/net.go +++ b/src/widgets/net.go @@ -11,6 +11,8 @@ import ( "github.com/cjbassi/gotop/src/utils" ) +type NetInterface string + type NetWidget struct { *ui.SparklineGroup updateInterval time.Duration @@ -18,9 +20,10 @@ type NetWidget struct { // used to calculate recent network activity totalBytesRecv uint64 totalBytesSent uint64 + NetInterface string } -func NewNetWidget() *NetWidget { +func NewNetWidget(netInterface string) *NetWidget { recvSparkline := ui.NewSparkline() recvSparkline.Data = []int{} @@ -31,8 +34,12 @@ func NewNetWidget() *NetWidget { self := &NetWidget{ SparklineGroup: spark, updateInterval: time.Second, + NetInterface: netInterface, } self.Title = " Network Usage " + if netInterface != "all" { + self.Title = fmt.Sprintf(" %s Usage ", netInterface) + } self.update() @@ -58,7 +65,10 @@ func (self *NetWidget) update() { var totalBytesSent uint64 for _, _interface := range interfaces { // ignore VPN interface - if _interface.Name != "tun0" { + if _interface.Name != "tun0" && self.NetInterface == "all" { + totalBytesRecv += _interface.BytesRecv + totalBytesSent += _interface.BytesSent + } else if _interface.Name == self.NetInterface { totalBytesRecv += _interface.BytesRecv totalBytesSent += _interface.BytesSent } |