mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-07 05:31:20 +02:00
Move dashboard package into a common location where both Talos and talosctl can use it. Add support for overriding stdin, stdout, stderr and ctt in process runner. Create a dashboard service which runs the dashboard on /dev/tty2. Redirect kernel messages to tty1 and switch to tty2 after starting the dashboard on it. Related to siderolabs/talos#6841, siderolabs/talos#4791. Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package components
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
|
|
ui "github.com/gizak/termui/v3"
|
|
"github.com/gizak/termui/v3/widgets"
|
|
|
|
"github.com/siderolabs/talos/internal/pkg/dashboard/data"
|
|
)
|
|
|
|
// SystemGauges quickly show CPU/mem load.
|
|
type SystemGauges struct {
|
|
ui.Block
|
|
|
|
cpuGauge *widgets.Gauge
|
|
memGauge *widgets.Gauge
|
|
}
|
|
|
|
// NewSystemGauges creates SystemGauges.
|
|
func NewSystemGauges() *SystemGauges {
|
|
widget := &SystemGauges{
|
|
Block: *ui.NewBlock(),
|
|
}
|
|
|
|
widget.cpuGauge = widgets.NewGauge()
|
|
widget.cpuGauge.Border = false
|
|
widget.cpuGauge.Title = "CPU"
|
|
widget.memGauge = widgets.NewGauge()
|
|
widget.memGauge.Title = "MEM"
|
|
widget.memGauge.Border = false
|
|
|
|
return widget
|
|
}
|
|
|
|
// Update implements DataWidget interface.
|
|
func (widget *SystemGauges) Update(node string, data *data.Data) {
|
|
nodeData := data.Nodes[node]
|
|
|
|
if nodeData == nil {
|
|
widget.cpuGauge.Label = noData
|
|
widget.cpuGauge.Percent = 0
|
|
widget.memGauge.Label = noData
|
|
widget.memGauge.Percent = 0
|
|
} else {
|
|
memUsed := nodeData.MemUsage()
|
|
|
|
widget.memGauge.Percent = int(math.Round(memUsed * 100.0))
|
|
widget.memGauge.Label = fmt.Sprintf("%.1f%%", memUsed*100.0)
|
|
|
|
cpuUsed := nodeData.CPUUsageByName("usage")
|
|
|
|
widget.cpuGauge.Percent = int(math.Round(cpuUsed * 100.0))
|
|
widget.cpuGauge.Label = fmt.Sprintf("%.1f%%", cpuUsed*100.0)
|
|
}
|
|
}
|
|
|
|
// Draw implements io.Drawable.
|
|
func (widget *SystemGauges) Draw(buf *ui.Buffer) {
|
|
width := widget.Dx()
|
|
height := widget.Dy()
|
|
|
|
y := 0
|
|
itemHeight := 2
|
|
|
|
for _, item := range []ui.Drawable{widget.cpuGauge, widget.memGauge} {
|
|
item.SetRect(widget.Min.X, widget.Min.Y+y, widget.Min.X+width, widget.Min.Y+y+itemHeight+1)
|
|
item.Draw(buf)
|
|
|
|
y += itemHeight
|
|
|
|
if y > height {
|
|
break
|
|
}
|
|
}
|
|
}
|