summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-02-14 07:52:33 -0600
committerSean E. Russell <ser@ser1.net>2020-02-14 07:52:33 -0600
commit64d4a81212a43a4b805b92963fd4da230b3ca313 (patch)
tree0d4b60ca935fce9fafb92a311fe4178529365f36
parent7594f3ecec8d830fe4241c9a01f9939c932bb132 (diff)
parentfcdb71bfad2c782a480e980821f085e090cb437c (diff)
Merge remote-tracking branch 'mattLLVW/feature/network_interface_list'
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md4
-rw-r--r--cmd/gotop/main.go7
-rw-r--r--config.go1
-rw-r--r--go.mod8
-rw-r--r--go.sum17
-rw-r--r--widgets/net.go30
7 files changed, 45 insertions, 23 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ba159b..28af61d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ Bug fixes & pull requests
- FIX Rowspan in a column loses widgets in later columns
- Merged pull request for README clean-ups (theverything:add-missing-option-to-readme)
- Merge Nord color scheme (jrswab:nordColorScheme)
+- Merge support for multiple (and filtering) network interfaces (mattLLVW:feature/network_interface_list)
## [3.1.0] - 2020-02-13
diff --git a/README.md b/README.md
index 2377e5f..6f1061c 100644
--- a/README.md
+++ b/README.md
@@ -155,6 +155,10 @@ build massive edifices, you're in for disappointment.
`-i`, `--interface=NAME` Select network interface [default: all].
`-l`, `--layout=NAME` Choose a layout. gotop searches for a file by NAME in \$XDG_CONFIG_HOME/gotop, then relative to the current path. "-" reads a layout from stdin, allowing for simple, one-off layouts such as `echo net | gotop -l -`
+Several interfaces can be defined using comma separated values.
+
+Interfaces can also be ignored using `!`
+
## Built With
- [gizak/termui](https://github.com/gizak/termui)
diff --git a/cmd/gotop/main.go b/cmd/gotop/main.go
index e9a9a02..bf9b72d 100644
--- a/cmd/gotop/main.go
+++ b/cmd/gotop/main.go
@@ -56,9 +56,13 @@ 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=NAME Select network interface [default: all].
-B, --bandwidth=bits Specify the number of bits per seconds.
-l, --layout=NAME Name of layout spec file for the UI. Looks first in $XDG_CONFIG_HOME/gotop, then as a path. Use "-" to pipe.
+ -i, --interface=NAME Select network interface [default: all].
+
+Several interfaces can be defined using comma separated values.
+
+Interfaces can also be ignored using !
Colorschemes:
default
@@ -139,6 +143,7 @@ Colorschemes:
if fahrenheit {
conf.TempScale = w.Fahrenheit
}
+ conf.NetInterface, _ = args["--interface"].(string)
return conf, nil
}
diff --git a/config.go b/config.go
index 55ea91b..7eff495 100644
--- a/config.go
+++ b/config.go
@@ -14,7 +14,6 @@ import (
// TODO: Merge #167 configuration file (jrswab:configFile111)
// TODO: Merge #157 FreeBSD fixes & Nvidia GPU support (kraust:master)
// TODO: Merge #156 Added temperatures for NVidia GPUs (azak-azkaran:master)
-// TODO: Merge #152 (implements #148 & #149) (mattLLVW:feature/network_interface_list)
// TODO: Merge #147 filtering subprocesses by substring (rephorm:filter)
// TODO: Merge #140 color-related fix (Tazer:master)
// TODO: Merge #135 linux console font (cmatsuoka:console-font)
diff --git a/go.mod b/go.mod
index 27bb259..e075085 100644
--- a/go.mod
+++ b/go.mod
@@ -1,17 +1,15 @@
module github.com/xxxserxxx/gotop
require (
- github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
+ github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/distatus/battery v0.9.0
github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815
github.com/gizak/termui/v3 v3.0.0
- github.com/go-ole/go-ole v1.2.1 // indirect
- github.com/mattn/go-runewidth v0.0.4 // indirect
- github.com/mitchellh/go-wordwrap v1.0.0 // indirect
+ github.com/go-ole/go-ole v1.2.4 // indirect
github.com/shirou/gopsutil v2.18.11+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/stretchr/testify v1.4.0
- golang.org/x/sys v0.0.0-20190116161447-11f53e031339 // indirect
+ golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
)
diff --git a/go.sum b/go.sum
index c3d399a..91a8c8b 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
-github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
+github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
+github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd h1:XtfPmj9tQRilnrEmI1HjQhxXWRhEM+m8CACtaMJE/kM=
github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd/go.mod h1:vjcQJUZJYD3MeVGhtZXSMnCHfUNZxsyYzJt90eCYxK4=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
@@ -10,8 +10,8 @@ github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815 h1:HMAfwOa33y82Ia
github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:l7JNRynTRuqe45tpIyItHNqZWTxywYjp87MWTOnU5cg=
github.com/gizak/termui/v3 v3.0.0 h1:NYTUG6ig/sJK05O5FyhWemwlVPO8ilNpvS/PgRtrKAE=
github.com/gizak/termui/v3 v3.0.0/go.mod h1:uinu2dMdtMI+FTIdEFUJQT5y+KShnhQRshvPblXq3lY=
-github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
-github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
+github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
+github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -20,12 +20,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
-github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
-github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
-github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
-github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840=
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -40,8 +36,9 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 h1:Pn8fQdvx+z1avAi7fdM2kRYWQNxGlavNDSyzrQg2SsU=
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8=
-golang.org/x/sys v0.0.0-20190116161447-11f53e031339 h1:g/Jesu8+QLnA0CPzF3E1pURg0Byr7i6jLoX5sqjcAh0=
-golang.org/x/sys v0.0.0-20190116161447-11f53e031339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
+golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
diff --git a/widgets/net.go b/widgets/net.go
index dd051e8..c4ac8e8 100644
--- a/widgets/net.go
+++ b/widgets/net.go
@@ -3,6 +3,7 @@ package widgets
import (
"fmt"
"log"
+ "strings"
"time"
psNet "github.com/shirou/gopsutil/net"
@@ -16,8 +17,6 @@ const (
NET_INTERFACE_VPN = "tun0"
)
-type NetInterface string
-
type NetWidget struct {
*ui.SparklineGroup
updateInterval time.Duration
@@ -25,7 +24,7 @@ type NetWidget struct {
// used to calculate recent network activity
totalBytesRecv uint64
totalBytesSent uint64
- NetInterface string
+ NetInterface []string
}
func NewNetWidget(netInterface string) *NetWidget {
@@ -39,7 +38,7 @@ func NewNetWidget(netInterface string) *NetWidget {
self := &NetWidget{
SparklineGroup: spark,
updateInterval: time.Second,
- NetInterface: netInterface,
+ NetInterface: strings.Split(netInterface, ","),
}
self.Title = " Network Usage "
if netInterface != "all" {
@@ -68,9 +67,28 @@ func (self *NetWidget) update() {
var totalBytesRecv uint64
var totalBytesSent uint64
+ interfaceMap := make(map[string]bool)
+ // Default behaviour
+ interfaceMap[NET_INTERFACE_ALL] = true
+ interfaceMap[NET_INTERFACE_VPN] = false
+ // Build a map with wanted status for each interfaces.
+ for _, iface := range self.NetInterface {
+ if strings.HasPrefix(iface, "!") {
+ interfaceMap[strings.TrimPrefix(iface, "!")] = false
+ } else {
+ // if we specify a wanted interface, remove capture on all.
+ delete(interfaceMap, NET_INTERFACE_ALL)
+ interfaceMap[iface] = true
+ }
+ }
for _, _interface := range interfaces {
- // ignore VPN interface or filter interface by name
- if ((self.NetInterface == NET_INTERFACE_ALL) && (_interface.Name != NET_INTERFACE_VPN)) || (_interface.Name == self.NetInterface) {
+ wanted, ok := interfaceMap[_interface.Name]
+ if wanted && ok { // Simple case
+ totalBytesRecv += _interface.BytesRecv
+ totalBytesSent += _interface.BytesSent
+ } else if ok { // Present but unwanted
+ continue
+ } else if interfaceMap[NET_INTERFACE_ALL] { // Capture other
totalBytesRecv += _interface.BytesRecv
totalBytesSent += _interface.BytesSent
}