Merge pull request #144 from mattLLVW/feature/network_interface
select network interface
This commit is contained in:
commit
f6994e843d
@ -111,6 +111,7 @@ To make a custom colorscheme, check out the [template](./colorschemes/template.g
|
||||
`-a`, `--averagecpu` Show average CPU in the CPU widget.
|
||||
`-s`, `--statusbar` Show a statusbar with the time.
|
||||
`-b`, `--battery` Show battery level widget (`minimal` turns off). [preview](./assets/battery.png)
|
||||
`-i`, `--interface=NAME` Select network interface [default: all].
|
||||
|
||||
## Credits
|
||||
|
||||
|
5
main.go
5
main.go
@ -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=NAME 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)
|
||||
}
|
||||
|
@ -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(" Network Usage: %s ", netInterface)
|
||||
}
|
||||
|
||||
self.update()
|
||||
|
||||
@ -57,8 +64,8 @@ func (self *NetWidget) update() {
|
||||
var totalBytesRecv uint64
|
||||
var totalBytesSent uint64
|
||||
for _, _interface := range interfaces {
|
||||
// ignore VPN interface
|
||||
if _interface.Name != "tun0" {
|
||||
// ignore VPN interface or filter interface by name
|
||||
if (_interface.Name != "tun0" && self.NetInterface == "all") || (_interface.Name == self.NetInterface) {
|
||||
totalBytesRecv += _interface.BytesRecv
|
||||
totalBytesSent += _interface.BytesSent
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user