1
0
mirror of https://github.com/cjbassi/gotop.git synced 2025-04-25 13:49:00 +08:00
This commit is contained in:
matt LLVW 2019-05-14 18:09:17 +02:00
parent 21cd642424
commit 2be4549c15
2 changed files with 16 additions and 3 deletions

View File

@ -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)
}

View File

@ -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
}