Skip to content

Commit 1bf95ee

Browse files
fsgh42smira
authored andcommitted
feat: improve dashboard uptime display
* display dashboard uptime in days when >= 24h Signed-off-by: Fritz Schaal <fritz.schaal@siderolabs.com>
1 parent 055add7 commit 1bf95ee

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

internal/pkg/dashboard/components/header.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ func (widget *Header) humanizeCPUFrequency(mhz float64) string {
111111
return fmt.Sprintf("%s%s", humanize.Ftoa(value), unit)
112112
}
113113

114+
// formatUptime returns a duration in a human readable form.
115+
//
116+
// If d>24h returns format "23d72h3m5s", otherwise "72h3m5s".
117+
func formatUptime(d time.Duration) string {
118+
const day = 24 * time.Hour
119+
120+
d = d.Round(time.Second)
121+
if d >= day {
122+
uptimeDays := d / day
123+
uptimeRest := d % day
124+
125+
return fmt.Sprintf("%dd%s", uptimeDays, uptimeRest)
126+
}
127+
128+
return d.String()
129+
}
130+
114131
// Spinner is a set of characters compatible with Linux virtual console CP437.
115132
var spinner = []string{"\u2510", "\u2518", "\u2514", "\u250C"}
116133

@@ -152,7 +169,8 @@ func (widget *Header) updateNodeAPIData(node string, data *apidata.Node) {
152169
}
153170

154171
if data.SystemStat != nil && data.SystemStat.BootTime != 0 {
155-
nodeData.uptime = time.Since(time.Unix(int64(data.SystemStat.GetBootTime()), 0)).Round(time.Second).String()
172+
uptime := time.Since(time.Unix(int64(data.SystemStat.GetBootTime()), 0))
173+
nodeData.uptime = formatUptime(uptime)
156174
} else {
157175
nodeData.uptime = notAvailable
158176
}

0 commit comments

Comments
 (0)