summaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-04-16 13:28:18 -0500
committerSean E. Russell <ser@ser1.net>2020-04-16 13:28:18 -0500
commit9e1b63be3250661124babf270f8a13326ef0d2f0 (patch)
treef2ae4b5cf45e5797e005ada72d1087f3c50dc4ee /widgets
parentd22c36e7195b80c199c25a7a0ed2525555e1de00 (diff)
Closes #46, option to display network traffic as mbps. This can be set on the command line with --mbps, or toggled while running with `b`
Diffstat (limited to 'widgets')
-rw-r--r--widgets/batterygauge.go1
-rw-r--r--widgets/help.go3
-rw-r--r--widgets/net.go31
3 files changed, 25 insertions, 10 deletions
diff --git a/widgets/batterygauge.go b/widgets/batterygauge.go
index d447713..534c1cf 100644
--- a/widgets/batterygauge.go
+++ b/widgets/batterygauge.go
@@ -12,7 +12,6 @@ import (
. "github.com/xxxserxxx/gotop/v3/termui"
)
-// FIXME 3.5.1 is 0% always
type BatteryGauge struct {
*Gauge
metric prometheus.Gauge
diff --git a/widgets/help.go b/widgets/help.go
index 8aab35d..012ca9d 100644
--- a/widgets/help.go
+++ b/widgets/help.go
@@ -40,6 +40,9 @@ Process filtering:
CPU and Mem graph scaling:
- h: scale in
- l: scale out
+
+Network:
+ - b: toggle between mbps and scaled bytes per second
`
type HelpMenu struct {
diff --git a/widgets/net.go b/widgets/net.go
index 3f03936..249d0c2 100644
--- a/widgets/net.go
+++ b/widgets/net.go
@@ -28,6 +28,7 @@ type NetWidget struct {
NetInterface []string
sentMetric prometheus.Counter
recvMetric prometheus.Counter
+ Mbps bool
}
// TODO: state:merge #169 % option for network use (jrswab/networkPercentage)
@@ -144,19 +145,31 @@ func (self *NetWidget) update() {
self.totalBytesRecv = totalBytesRecv
self.totalBytesSent = totalBytesSent
+ rx, tx := "RX/s", "TX/s"
+ if self.Mbps {
+ rx, tx = "mbps", "mbps"
+ }
+ format := " %s: %9.1f %2s/s"
+
+ var total, recent uint64
+ var label, unitRecent, rate string
+ var recentConverted float64
// render widget titles
for i := 0; i < 2; i++ {
- total, label, recent := func() (uint64, string, uint64) {
- if i == 0 {
- return totalBytesRecv, "RX", recentBytesRecv
- }
- return totalBytesSent, "TX", recentBytesSent
- }()
+ if i == 0 {
+ total, label, rate, recent = totalBytesRecv, "RX", rx, recentBytesRecv
+ } else {
+ total, label, rate, recent = totalBytesSent, "TX", tx, recentBytesSent
+ }
- recentConverted, unitRecent := utils.ConvertBytes(uint64(recent))
- totalConverted, unitTotal := utils.ConvertBytes(uint64(total))
+ totalConverted, unitTotal := utils.ConvertBytes(total)
+ if self.Mbps {
+ recentConverted, unitRecent, format = float64(recent)*0.000008, "", " %s: %11.3f %2s"
+ } else {
+ recentConverted, unitRecent = utils.ConvertBytes(recent)
+ }
self.Lines[i].Title1 = fmt.Sprintf(" Total %s: %5.1f %s", label, totalConverted, unitTotal)
- self.Lines[i].Title2 = fmt.Sprintf(" %s/s: %9.1f %2s/s", label, recentConverted, unitRecent)
+ self.Lines[i].Title2 = fmt.Sprintf(format, rate, recentConverted, unitRecent)
}
}