Improve list-nodes command output (#681)
tidied up list-nodes command output: made the table narrower (to fit on the screen); made numbers humanized; added nodes state (useful with SHUTTING_DOWN state); added retransmitted packets per second.
This commit is contained in:
+39
-25
@@ -4,8 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -153,47 +155,59 @@ func listNodes(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table := tablewriter.NewWriter(os.Stdout)
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
|
table.SetRowLine(true)
|
||||||
|
table.SetAutoWrapText(false)
|
||||||
table.SetHeader([]string{
|
table.SetHeader([]string{
|
||||||
"ID", "IP Address", "Region",
|
"ID", "IP Address", "Region",
|
||||||
"CPUs", "CPU Usage", "Load",
|
"CPUs", "CPU Usage /\nLoad Avg",
|
||||||
"Clients", "Rooms", "Tracks In/Out",
|
"Rooms", "Clients /\nTracks In/Out",
|
||||||
"Bytes In/Out", "Packets In/Out",
|
"Bytes/s In/Out /\nBytes Total", "Packets/s In/Out /\nPackets Total",
|
||||||
"Nack", "Retransmits",
|
"Nack/s /\nNack Total", "Retrans/s /\nRetrans Total",
|
||||||
"Bps In/Out", "Pps In/Out", "Nack/Sec",
|
"Started At /\nUpdated At",
|
||||||
"Started At", "Updated At",
|
|
||||||
})
|
})
|
||||||
|
table.SetColumnAlignment([]int{
|
||||||
|
tablewriter.ALIGN_CENTER, tablewriter.ALIGN_CENTER, tablewriter.ALIGN_CENTER,
|
||||||
|
tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT,
|
||||||
|
tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT,
|
||||||
|
tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT,
|
||||||
|
tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT,
|
||||||
|
tablewriter.ALIGN_CENTER,
|
||||||
|
})
|
||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
stats := node.Stats
|
stats := node.Stats
|
||||||
|
|
||||||
|
// Id and state
|
||||||
|
idAndState := fmt.Sprintf("%s\n(%s)", node.Id, node.State.Enum().String())
|
||||||
|
|
||||||
// System stats
|
// System stats
|
||||||
cpus := strconv.Itoa(int(stats.NumCpus))
|
cpus := strconv.Itoa(int(stats.NumCpus))
|
||||||
cpuUsage := fmt.Sprintf("%.2f %%", stats.CpuLoad*100)
|
cpuUsageAndLoadAvg := fmt.Sprintf("%.2f %%\n%.2f %.2f %.2f", stats.CpuLoad*100,
|
||||||
loadAvg := fmt.Sprintf("%.2f, %.2f, %.2f", stats.LoadAvgLast1Min, stats.LoadAvgLast5Min, stats.LoadAvgLast15Min)
|
stats.LoadAvgLast1Min, stats.LoadAvgLast5Min, stats.LoadAvgLast15Min)
|
||||||
|
|
||||||
// Room stats
|
// Room stats
|
||||||
clients := strconv.Itoa(int(stats.NumClients))
|
|
||||||
rooms := strconv.Itoa(int(stats.NumRooms))
|
rooms := strconv.Itoa(int(stats.NumRooms))
|
||||||
tracks := fmt.Sprintf("%d / %d", stats.NumTracksIn, stats.NumTracksOut)
|
clientsAndTracks := fmt.Sprintf("%d\n%d / %d", stats.NumClients, stats.NumTracksIn, stats.NumTracksOut)
|
||||||
|
|
||||||
// Packet stats
|
// Packet stats
|
||||||
bytes := fmt.Sprintf("%d / %d", stats.BytesIn, stats.BytesOut)
|
bytes := fmt.Sprintf("%sps / %sps\n%s / %s", humanize.Bytes(uint64(stats.BytesInPerSec)), humanize.Bytes(uint64(stats.BytesOutPerSec)),
|
||||||
packets := fmt.Sprintf("%d / %d", stats.PacketsIn, stats.PacketsOut)
|
humanize.Bytes(stats.BytesIn), humanize.Bytes(stats.BytesOut))
|
||||||
nack := strconv.Itoa(int(stats.NackTotal))
|
packets := fmt.Sprintf("%s / %s\n%s / %s", humanize.Comma(int64(stats.PacketsInPerSec)), humanize.Comma(int64(stats.PacketsOutPerSec)),
|
||||||
retransmit := strconv.Itoa(int(stats.RetransmitPacketsOut))
|
strings.TrimSpace(humanize.SIWithDigits(float64(stats.PacketsIn), 2, "")), strings.TrimSpace(humanize.SIWithDigits(float64(stats.PacketsOut), 2, "")))
|
||||||
bps := fmt.Sprintf("%.2f / %.2f", stats.BytesInPerSec, stats.BytesOutPerSec)
|
nacks := fmt.Sprintf("%.2f\n%s", stats.NackPerSec, strings.TrimSpace(humanize.SIWithDigits(float64(stats.NackTotal), 2, "")))
|
||||||
packetsPerSec := fmt.Sprintf("%.2f / %.2f", stats.PacketsInPerSec, stats.PacketsOutPerSec)
|
retransmit := fmt.Sprintf("%.2f\n%s", stats.RetransmitPacketsOutPerSec, strings.TrimSpace(humanize.SIWithDigits(float64(stats.RetransmitPacketsOut), 2, "")))
|
||||||
nackPerSec := fmt.Sprintf("%f", stats.NackPerSec)
|
|
||||||
|
|
||||||
startedAt := time.Unix(stats.StartedAt, 0).String()
|
// Date
|
||||||
updatedAt := time.Unix(stats.UpdatedAt, 0).String()
|
startedAndUpdated := fmt.Sprintf("%s\n%s", time.Unix(stats.StartedAt, 0).UTC().UTC().Format("2006-01-02 15:04:05"),
|
||||||
|
time.Unix(stats.UpdatedAt, 0).UTC().Format("2006-01-02 15:04:05"))
|
||||||
|
|
||||||
table.Append([]string{
|
table.Append([]string{
|
||||||
node.Id, node.Ip, node.Region,
|
idAndState, node.Ip, node.Region,
|
||||||
cpus, cpuUsage, loadAvg,
|
cpus, cpuUsageAndLoadAvg,
|
||||||
clients, rooms, tracks,
|
rooms, clientsAndTracks,
|
||||||
bytes, packets, nack, retransmit,
|
bytes, packets,
|
||||||
bps, packetsPerSec, nackPerSec,
|
nacks, retransmit,
|
||||||
startedAt, updatedAt,
|
startedAndUpdated,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ go 1.17
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bep/debounce v1.2.0
|
github.com/bep/debounce v1.2.0
|
||||||
|
github.com/dustin/go-humanize v1.0.0
|
||||||
github.com/elliotchance/orderedmap v1.4.0
|
github.com/elliotchance/orderedmap v1.4.0
|
||||||
github.com/gammazero/deque v0.1.0
|
github.com/gammazero/deque v0.1.0
|
||||||
github.com/gammazero/workerpool v1.1.2
|
github.com/gammazero/workerpool v1.1.2
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
|
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||||
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k=
|
github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k=
|
||||||
github.com/eapache/channels v1.1.0/go.mod h1:jMm2qB5Ubtg9zLd+inMZd2/NUvXgzmWXsDaLyQIGfH0=
|
github.com/eapache/channels v1.1.0/go.mod h1:jMm2qB5Ubtg9zLd+inMZd2/NUvXgzmWXsDaLyQIGfH0=
|
||||||
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
|
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
|
||||||
|
|||||||
Reference in New Issue
Block a user