Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/app/service/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d
var currentInfo dto.DashboardCurrent
hostInfo, _ := psutil.HOST.GetHostInfo(false)
currentInfo.Uptime = hostInfo.Uptime
currentInfo.TimeSinceUptime = time.Now().Add(-time.Duration(hostInfo.Uptime) * time.Second).Format(constant.DateTimeLayout)
currentInfo.TimeSinceUptime = time.Unix(int64(hostInfo.BootTime), 0).Format(constant.DateTimeLayout)
currentInfo.Procs = hostInfo.Procs
currentInfo.CPUTotal, _ = psutil.CPUInfo.GetLogicalCores(false)

Expand Down
7 changes: 5 additions & 2 deletions frontend/src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ export function getBrowserLang() {
return defaultBrowserLang;
}

export function loadUpTime(uptime: number) {
export function loadUpTime(timeSince: string) {
const targetTime = new Date(timeSince);
const currentTime = new Date();
const uptime = (currentTime.getTime() - targetTime.getTime()) / 1000;
if (uptime <= 0) {
return '-';
}
let days = Math.floor(uptime / 86400);
let hours = Math.floor((uptime % 86400) / 3600);
let minutes = Math.floor((uptime % 3600) / 60);
let seconds = uptime % 60;
let seconds = Math.floor(uptime % 60);
if (days !== 0) {
return (
days +
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
<template #label>
<span class="system-label">{{ $t('home.runningTime') }}</span>
</template>
{{ loadUpTime(currentInfo.uptime) }}
{{ loadUpTime(currentInfo.timeSinceUptime) }}
</el-descriptions-item>
</el-descriptions>
</el-scrollbar>
Expand Down Expand Up @@ -689,7 +689,7 @@ const handleCopy = () => {
'\n' +
i18n.global.t('home.runningTime') +
': ' +
loadUpTime(currentInfo.value.uptime) +
loadUpTime(currentInfo.value.timeSinceUptime) +
'\n';
copyText(content);
};
Expand Down
Loading