File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
internal/pkg/dashboard/components Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff 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.
115132var 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 }
You can’t perform that action at this time.
0 commit comments