show rtt in server list
@@ -22,6 +22,7 @@ import (
"sort"
"sync"
"sync/atomic"
+ "time"
"github.com/dustin/go-humanize"
"github.com/nats-io/nats-server/v2/server"
@@ -81,11 +82,12 @@ func (c *SrvLsCmd) list(_ *kingpin.ParseContext) error {
connections = 0
memory int64 = 0
slow int64 = 0
+ start = time.Now()
)
table := tablewriter.CreateTable()
table.AddTitle("Server Overview")
- table.AddHeaders("Name", "Cluster", "IP", "Version", "Conns", "Routes", "GWs", "Mem", "CPU", "Slow", "Uptime")
+ table.AddHeaders("Name", "Cluster", "IP", "Version", "Conns", "Routes", "GWs", "Mem", "CPU", "Slow", "Uptime", "RTT")
sub, err := ec.Subscribe(nc.NewRespInbox(), func(ssm *server.ServerStatsMsg) {
last := atomic.AddUint32(&seen, 1)
@@ -117,7 +119,7 @@ func (c *SrvLsCmd) list(_ *kingpin.ParseContext) error {
results = append(results, ssm)
mu.Unlock()
- table.AddRow(ssm.Server.Name, ssm.Server.Cluster, ssm.Server.Host, ssm.Server.Version, ssm.Stats.Connections, len(ssm.Stats.Routes), len(ssm.Stats.Gateways), humanize.IBytes(uint64(ssm.Stats.Mem)), fmt.Sprintf("%.1f", ssm.Stats.CPU), ssm.Stats.SlowConsumers, humanizeTime(ssm.Stats.Start))
+ table.AddRow(ssm.Server.Name, ssm.Server.Cluster, ssm.Server.Host, ssm.Server.Version, ssm.Stats.Connections, len(ssm.Stats.Routes), len(ssm.Stats.Gateways), humanize.IBytes(uint64(ssm.Stats.Mem)), fmt.Sprintf("%.1f", ssm.Stats.CPU), ssm.Stats.SlowConsumers, humanizeTime(ssm.Stats.Start), time.Since(start))
if last == c.expect {
cancel()
@@ -149,7 +151,7 @@ func (c *SrvLsCmd) list(_ *kingpin.ParseContext) error {
}
table.AddSeparator()
- table.AddRow("", fmt.Sprintf("%d Clusters", len(clusters)), fmt.Sprintf("%d Servers", servers), "", connections, "", "", humanize.IBytes(uint64(memory)), "", slow, "")
+ table.AddRow("", fmt.Sprintf("%d Clusters", len(clusters)), fmt.Sprintf("%d Servers", servers), "", connections, "", "", humanize.IBytes(uint64(memory)), "", slow, "", "")
fmt.Print(table.Render())
if c.expect != 0 && c.expect != seen {
