list-nodes command action (#87)

* list-nodes command action

* refactor stats into a package

* store existing stats in redis, more refactoring

* dz review: atomic load
This commit is contained in:
Mathew Kamkar
2021-08-24 10:14:39 -07:00
committed by GitHub
parent a8b0125e42
commit f5466c74e6
15 changed files with 428 additions and 294 deletions
+43
View File
@@ -3,10 +3,14 @@ package main
import (
"fmt"
"os"
"strconv"
"time"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/service"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/utils"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
)
@@ -123,3 +127,42 @@ func createToken(c *cli.Context) error {
return nil
}
func listNodes(c *cli.Context) error {
conf, err := getConfig(c)
if err != nil {
return err
}
currentNode, err := routing.NewLocalNode(conf)
if err != nil {
return err
}
router, err := service.InitializeRouter(conf, currentNode)
if err != nil {
return err
}
nodes, err := router.ListNodes()
if err != nil {
return err
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "IP Address", "Num CPUs", "Num Clients", "Num Rooms", "Num Tracks In", "Num Tracks Out", "Started At", "Updated At"})
for _, node := range nodes {
cpus := strconv.Itoa(int(node.NumCpus))
clients := strconv.Itoa(int(node.Stats.NumClients))
rooms := strconv.Itoa(int(node.Stats.NumRooms))
tracksIn := strconv.Itoa(int(node.Stats.NumTracksIn))
tracksOut := strconv.Itoa(int(node.Stats.NumTracksOut))
startedAt := time.Unix(node.Stats.StartedAt, 0).String()
updatedAt := time.Unix(node.Stats.UpdatedAt, 0).String()
table.Append([]string{node.Id, node.Ip, cpus, clients, rooms, tracksIn, tracksOut, startedAt, updatedAt})
}
table.Render()
return nil
}
+5
View File
@@ -123,6 +123,11 @@ func main() {
},
},
},
{
Name: "list-nodes",
Usage: "list all nodes",
Action: listNodes,
},
},
Version: version.Version,
}