Utku Ozdemir f55f5df739
feat: move dashboard package & run it in tty2
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>
2023-02-28 12:00:25 +01:00

49 lines
1.2 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"
"time"
"github.com/gizak/termui/v3/widgets"
"github.com/siderolabs/talos/internal/pkg/dashboard/data"
)
// TopLine represents the top bar with host info.
type TopLine struct {
widgets.Paragraph
}
// NewTopLine initializes TopLine.
func NewTopLine() *TopLine {
topline := &TopLine{
Paragraph: *widgets.NewParagraph(),
}
topline.Border = false
topline.Text = noData
return topline
}
// Update implements the DataWidget interface.
func (widget *TopLine) Update(node string, data *data.Data) {
nodeData := data.Nodes[node]
if nodeData == nil {
widget.Text = "n/a"
} else {
widget.Text = fmt.Sprintf("[%s](fg:yellow,mod:bold) (%s): uptime %s, %d cores, %d procs",
nodeData.Hostname.GetHostname(),
nodeData.Version.GetVersion().GetTag(),
time.Since(time.Unix(int64(nodeData.SystemStat.GetBootTime()), 0)).Round(time.Second),
len(nodeData.CPUsInfo.GetCpuInfo()),
len(nodeData.Processes.GetProcesses()),
)
}
}