add memory used and total to node stats (#1293)
* add memory used and total to node stats * raja review: consistency * update protocol
This commit is contained in:
@@ -171,17 +171,18 @@ func listNodes(c *cli.Context) error {
|
|||||||
table.SetHeader([]string{
|
table.SetHeader([]string{
|
||||||
"ID", "IP Address", "Region",
|
"ID", "IP Address", "Region",
|
||||||
"CPUs", "CPU Usage\nLoad Avg",
|
"CPUs", "CPU Usage\nLoad Avg",
|
||||||
|
"Memory Used/Total",
|
||||||
"Rooms", "Clients\nTracks In/Out",
|
"Rooms", "Clients\nTracks In/Out",
|
||||||
"Bytes/s In/Out\nBytes Total", "Packets/s In/Out\nPackets Total", "System Dropped Pkts/s\nPkts/s Out / Dropped",
|
"Bytes/s In/Out\nBytes Total", "Packets/s In/Out\nPackets Total", "System Dropped Pkts/s\nPkts/s Out/Dropped",
|
||||||
"Nack/s\nNack Total", "Retrans/s\nRetrans Total",
|
"Nack/s\nNack Total", "Retrans/s\nRetrans Total",
|
||||||
"Started At\nUpdated At",
|
"Started At\nUpdated At",
|
||||||
})
|
})
|
||||||
table.SetColumnAlignment([]int{
|
table.SetColumnAlignment([]int{
|
||||||
tablewriter.ALIGN_CENTER, tablewriter.ALIGN_CENTER, tablewriter.ALIGN_CENTER,
|
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_RIGHT,
|
||||||
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_RIGHT,
|
tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT,
|
||||||
tablewriter.ALIGN_CENTER,
|
tablewriter.ALIGN_CENTER,
|
||||||
})
|
})
|
||||||
@@ -196,6 +197,7 @@ func listNodes(c *cli.Context) error {
|
|||||||
cpus := strconv.Itoa(int(stats.NumCpus))
|
cpus := strconv.Itoa(int(stats.NumCpus))
|
||||||
cpuUsageAndLoadAvg := fmt.Sprintf("%.2f %%\n%.2f %.2f %.2f", stats.CpuLoad*100,
|
cpuUsageAndLoadAvg := fmt.Sprintf("%.2f %%\n%.2f %.2f %.2f", stats.CpuLoad*100,
|
||||||
stats.LoadAvgLast1Min, stats.LoadAvgLast5Min, stats.LoadAvgLast15Min)
|
stats.LoadAvgLast1Min, stats.LoadAvgLast5Min, stats.LoadAvgLast15Min)
|
||||||
|
memUsage := fmt.Sprintf("%s / %s", humanize.Bytes(stats.MemoryUsed), humanize.Bytes(stats.MemoryTotal))
|
||||||
|
|
||||||
// Room stats
|
// Room stats
|
||||||
rooms := strconv.Itoa(int(stats.NumRooms))
|
rooms := strconv.Itoa(int(stats.NumRooms))
|
||||||
@@ -217,6 +219,7 @@ func listNodes(c *cli.Context) error {
|
|||||||
table.Append([]string{
|
table.Append([]string{
|
||||||
idAndState, node.Ip, node.Region,
|
idAndState, node.Ip, node.Region,
|
||||||
cpus, cpuUsageAndLoadAvg,
|
cpus, cpuUsageAndLoadAvg,
|
||||||
|
memUsage,
|
||||||
rooms, clientsAndTracks,
|
rooms, clientsAndTracks,
|
||||||
bytes, packets, sysPackets,
|
bytes, packets, sysPackets,
|
||||||
nacks, retransmit,
|
nacks, retransmit,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ require (
|
|||||||
github.com/jxskiss/base62 v1.1.0
|
github.com/jxskiss/base62 v1.1.0
|
||||||
github.com/livekit/mageutil v0.0.0-20221221221243-f361fbe40290
|
github.com/livekit/mageutil v0.0.0-20221221221243-f361fbe40290
|
||||||
github.com/livekit/mediatransportutil v0.0.0-20221007030528-7440725c362b
|
github.com/livekit/mediatransportutil v0.0.0-20221007030528-7440725c362b
|
||||||
github.com/livekit/protocol v1.3.2-0.20221228091932-fa87d56355d2
|
github.com/livekit/protocol v1.3.2-0.20230110201647-34cae0997a36
|
||||||
github.com/livekit/psrpc v0.2.1
|
github.com/livekit/psrpc v0.2.1
|
||||||
github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995
|
github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995
|
||||||
github.com/mackerelio/go-osstat v0.2.3
|
github.com/mackerelio/go-osstat v0.2.3
|
||||||
|
|||||||
@@ -233,8 +233,8 @@ github.com/livekit/mageutil v0.0.0-20221221221243-f361fbe40290 h1:ZVsQUuUOM9G7O3
|
|||||||
github.com/livekit/mageutil v0.0.0-20221221221243-f361fbe40290/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
|
github.com/livekit/mageutil v0.0.0-20221221221243-f361fbe40290/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
|
||||||
github.com/livekit/mediatransportutil v0.0.0-20221007030528-7440725c362b h1:RBNV8TckETSkIkKxcD12d8nZKVkB9GSY/sQlMoaruP4=
|
github.com/livekit/mediatransportutil v0.0.0-20221007030528-7440725c362b h1:RBNV8TckETSkIkKxcD12d8nZKVkB9GSY/sQlMoaruP4=
|
||||||
github.com/livekit/mediatransportutil v0.0.0-20221007030528-7440725c362b/go.mod h1:1Dlx20JPoIKGP45eo+yuj0HjeE25zmyeX/EWHiPCjFw=
|
github.com/livekit/mediatransportutil v0.0.0-20221007030528-7440725c362b/go.mod h1:1Dlx20JPoIKGP45eo+yuj0HjeE25zmyeX/EWHiPCjFw=
|
||||||
github.com/livekit/protocol v1.3.2-0.20221228091932-fa87d56355d2 h1:Kj7tg1YxRZFeTQLJNm8x8KIdhFTgLCQ6QFNDio/2bOM=
|
github.com/livekit/protocol v1.3.2-0.20230110201647-34cae0997a36 h1:SlWsB3XEt4fYYkcCeCES2V8CFkRYcX0ThdkNqWP4MPg=
|
||||||
github.com/livekit/protocol v1.3.2-0.20221228091932-fa87d56355d2/go.mod h1:gwCG03nKlHlC9hTjL4pXQpn783ALhmbyhq65UZxqbb8=
|
github.com/livekit/protocol v1.3.2-0.20230110201647-34cae0997a36/go.mod h1:gwCG03nKlHlC9hTjL4pXQpn783ALhmbyhq65UZxqbb8=
|
||||||
github.com/livekit/psrpc v0.2.1 h1:ph/4egUMueUPoh5PZ/Aw4v6SH3wAbA+2t/GyCbpPKTg=
|
github.com/livekit/psrpc v0.2.1 h1:ph/4egUMueUPoh5PZ/Aw4v6SH3wAbA+2t/GyCbpPKTg=
|
||||||
github.com/livekit/psrpc v0.2.1/go.mod h1:MCe0xLdFPXmzogPiLrM94JIJbctb9+fAv5qYPkY2DXw=
|
github.com/livekit/psrpc v0.2.1/go.mod h1:MCe0xLdFPXmzogPiLrM94JIJbctb9+fAv5qYPkY2DXw=
|
||||||
github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 h1:vOaY2qvfLihDyeZtnGGN1Law9wRrw8BMGCr1TygTvMw=
|
github.com/livekit/rtcscore-go v0.0.0-20220815072451-20ee10ae1995 h1:vOaY2qvfLihDyeZtnGGN1Law9wRrw8BMGCr1TygTvMw=
|
||||||
|
|||||||
@@ -85,18 +85,6 @@ func Init(nodeID string, nodeType livekit.NodeType) {
|
|||||||
initRoomStats(nodeID, nodeType)
|
initRoomStats(nodeID, nodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMemoryStats() (memoryLoad float32, err error) {
|
|
||||||
memInfo, err := memory.Get()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if memInfo.Total != 0 {
|
|
||||||
memoryLoad = float32(memInfo.Used) / float32(memInfo.Total)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetUpdatedNodeStats(prev *livekit.NodeStats, prevAverage *livekit.NodeStats) (*livekit.NodeStats, bool, error) {
|
func GetUpdatedNodeStats(prev *livekit.NodeStats, prevAverage *livekit.NodeStats) (*livekit.NodeStats, bool, error) {
|
||||||
loadAvg, err := loadavg.Get()
|
loadAvg, err := loadavg.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -108,9 +96,9 @@ func GetUpdatedNodeStats(prev *livekit.NodeStats, prevAverage *livekit.NodeStats
|
|||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
memoryLoad, _ := getMemoryStats()
|
|
||||||
// On MacOS, get "\"vm_stat\": executable file not found in $PATH" although it is in /usr/bin
|
// On MacOS, get "\"vm_stat\": executable file not found in $PATH" although it is in /usr/bin
|
||||||
// So, do not error out. Use the information if it is available.
|
// So, do not error out. Use the information if it is available.
|
||||||
|
memInfo, _ := memory.Get()
|
||||||
|
|
||||||
sysPackets, sysDroppedPackets, err := getTCStats()
|
sysPackets, sysDroppedPackets, err := getTCStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -166,12 +154,13 @@ func GetUpdatedNodeStats(prev *livekit.NodeStats, prevAverage *livekit.NodeStats
|
|||||||
ParticipantJoinPerSec: prevAverage.ParticipantJoinPerSec,
|
ParticipantJoinPerSec: prevAverage.ParticipantJoinPerSec,
|
||||||
NumCpus: numCPUs,
|
NumCpus: numCPUs,
|
||||||
CpuLoad: cpuLoad,
|
CpuLoad: cpuLoad,
|
||||||
|
MemoryTotal: memInfo.Total,
|
||||||
|
MemoryUsed: memInfo.Used,
|
||||||
LoadAvgLast1Min: float32(loadAvg.Loadavg1),
|
LoadAvgLast1Min: float32(loadAvg.Loadavg1),
|
||||||
LoadAvgLast5Min: float32(loadAvg.Loadavg5),
|
LoadAvgLast5Min: float32(loadAvg.Loadavg5),
|
||||||
LoadAvgLast15Min: float32(loadAvg.Loadavg15),
|
LoadAvgLast15Min: float32(loadAvg.Loadavg15),
|
||||||
SysPacketsOut: sysPackets,
|
SysPacketsOut: sysPackets,
|
||||||
SysPacketsDropped: sysDroppedPackets,
|
SysPacketsDropped: sysDroppedPackets,
|
||||||
MemoryLoad: memoryLoad,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update stats
|
// update stats
|
||||||
|
|||||||
Reference in New Issue
Block a user