Skip to content

Commit

Permalink
fix: fix dashboard crash when a non-existent node is specified
Browse files Browse the repository at this point in the history
Prevent dashboard from crashing when a dead/non-existent node is specified on `talosctl --nodes`.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
(cherry picked from commit f14928b)
  • Loading branch information
utkuozdemir authored and smira committed Apr 18, 2023
1 parent 664d8c9 commit c2e26e9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions internal/pkg/dashboard/components/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,38 +122,43 @@ func (widget *Header) redraw() {
}

func (widget *Header) updateNodeAPIData(node string, data *apidata.Node) {
sss := widget.getOrCreateNodeData(node)
nodeData := widget.getOrCreateNodeData(node)

if data == nil {
return
}

sss.cpuUsagePercent = fmt.Sprintf("%.1f%%", data.CPUUsageByName("usage")*100.0)
sss.memUsagePercent = fmt.Sprintf("%.1f%%", data.MemUsage()*100.0)
nodeData.cpuUsagePercent = fmt.Sprintf("%.1f%%", data.CPUUsageByName("usage")*100.0)
nodeData.memUsagePercent = fmt.Sprintf("%.1f%%", data.MemUsage()*100.0)

if data.Hostname != nil {
sss.hostname = data.Hostname.GetHostname()
nodeData.hostname = data.Hostname.GetHostname()
}

if data.Version != nil {
sss.version = data.Version.GetVersion().GetTag()
nodeData.version = data.Version.GetVersion().GetTag()
}

if data.SystemStat != nil {
sss.uptime = time.Since(time.Unix(int64(data.SystemStat.GetBootTime()), 0)).Round(time.Second).String()
nodeData.uptime = time.Since(time.Unix(int64(data.SystemStat.GetBootTime()), 0)).Round(time.Second).String()
}

if data.CPUsInfo != nil {
sss.numCPUs = fmt.Sprintf("%d", len(data.CPUsInfo.GetCpuInfo()))
sss.cpuFreq = widget.humanizeCPUFrequency(data.CPUsInfo.GetCpuInfo()[0].GetCpuMhz())
numCPUs := len(data.CPUsInfo.GetCpuInfo())

nodeData.numCPUs = fmt.Sprintf("%d", numCPUs)

if numCPUs > 0 {
nodeData.cpuFreq = widget.humanizeCPUFrequency(data.CPUsInfo.GetCpuInfo()[0].GetCpuMhz())
}
}

if data.Processes != nil {
sss.numProcesses = fmt.Sprintf("%d", len(data.Processes.GetProcesses()))
nodeData.numProcesses = fmt.Sprintf("%d", len(data.Processes.GetProcesses()))
}

if data.Memory != nil {
sss.totalMem = humanize.IBytes(data.Memory.GetMeminfo().GetMemtotal() << 10)
nodeData.totalMem = humanize.IBytes(data.Memory.GetMeminfo().GetMemtotal() << 10)
}
}

Expand Down

0 comments on commit c2e26e9

Please sign in to comment.