feat(system): add server startup time and uptime tracking
- Introduced `started_at` and `uptime_seconds` fields to the `SystemInfo` structure for tracking server boot time and uptime. - Updated the `GetSystemInfo` handler to populate these new fields based on server runtime. - Enhanced the frontend to display server startup time and uptime in the system information view, improving visibility for users. - Added localization support for new labels and descriptions related to server uptime and startup time in multiple languages.
This commit is contained in:
@@ -15,6 +15,10 @@ export interface SystemInfo {
|
||||
* When non-empty, the system info view should surface a troubleshooting
|
||||
* banner (see docs/migration-troubleshooting.md). */
|
||||
db_migration_error?: string
|
||||
/** Server process boot time (RFC3339, UTC). */
|
||||
started_at?: string
|
||||
/** Seconds since process start. */
|
||||
uptime_seconds?: number
|
||||
}
|
||||
|
||||
export interface PlaceholderDefinition {
|
||||
|
||||
@@ -2984,6 +2984,14 @@ export default {
|
||||
buildTimeDescription: 'Time when the system was built',
|
||||
goVersionLabel: 'Go Version',
|
||||
goVersionDescription: 'Go language version used by the backend',
|
||||
startedAtLabel: 'Service started at',
|
||||
startedAtDescription: 'When the current backend process last started',
|
||||
uptimeLabel: 'Uptime',
|
||||
uptimeDescription: 'How long the service has been running since this start',
|
||||
uptimeDays: '{n}d',
|
||||
uptimeHours: '{n}h',
|
||||
uptimeMinutes: '{n}m',
|
||||
uptimeSeconds: '{n}s',
|
||||
dbVersionLabel: 'Database Version',
|
||||
dbVersionDescription: 'Current database migration version',
|
||||
dbMigrationFailedTag: 'Migration failed',
|
||||
|
||||
@@ -2216,6 +2216,14 @@ export default {
|
||||
buildTimeDescription: "시스템이 빌드된 시간",
|
||||
goVersionLabel: "Go 버전",
|
||||
goVersionDescription: "백엔드에서 사용하는 Go 언어 버전",
|
||||
startedAtLabel: "서비스 시작 시각",
|
||||
startedAtDescription: "현재 백엔드 프로세스가 마지막으로 시작된 시각",
|
||||
uptimeLabel: "가동 시간",
|
||||
uptimeDescription: "이번 시작 이후 연속 실행된 시간",
|
||||
uptimeDays: "{n}일",
|
||||
uptimeHours: "{n}시간",
|
||||
uptimeMinutes: "{n}분",
|
||||
uptimeSeconds: "{n}초",
|
||||
dbVersionLabel: "데이터베이스 버전",
|
||||
dbVersionDescription: "현재 데이터베이스 마이그레이션 버전",
|
||||
dbMigrationFailedTag: "마이그레이션 실패",
|
||||
|
||||
@@ -1935,6 +1935,14 @@ export default {
|
||||
buildTimeDescription: 'Время, когда система была собрана',
|
||||
goVersionLabel: 'Версия Go',
|
||||
goVersionDescription: 'Версия языка Go, используемая backend',
|
||||
startedAtLabel: 'Время запуска сервиса',
|
||||
startedAtDescription: 'Момент последнего запуска текущего процесса backend',
|
||||
uptimeLabel: 'Время работы',
|
||||
uptimeDescription: 'Непрерывное время работы с момента этого запуска',
|
||||
uptimeDays: '{n} д',
|
||||
uptimeHours: '{n} ч',
|
||||
uptimeMinutes: '{n} мин',
|
||||
uptimeSeconds: '{n} с',
|
||||
dbVersionLabel: 'Версия базы данных',
|
||||
dbVersionDescription: 'Текущая версия миграции базы данных',
|
||||
dbMigrationFailedTag: 'Миграция не удалась',
|
||||
|
||||
@@ -2202,6 +2202,14 @@ export default {
|
||||
buildTimeDescription: "系统构建的时间",
|
||||
goVersionLabel: "Go 版本",
|
||||
goVersionDescription: "后端使用的 Go 语言版本",
|
||||
startedAtLabel: "服务启动时间",
|
||||
startedAtDescription: "当前后端进程最近一次启动的时刻",
|
||||
uptimeLabel: "运行时长",
|
||||
uptimeDescription: "自本次启动以来的连续运行时间",
|
||||
uptimeDays: "{n} 天",
|
||||
uptimeHours: "{n} 小时",
|
||||
uptimeMinutes: "{n} 分钟",
|
||||
uptimeSeconds: "{n} 秒",
|
||||
dbVersionLabel: "数据库版本",
|
||||
dbVersionDescription: "当前数据库迁移版本号",
|
||||
dbMigrationFailedTag: "迁移失败",
|
||||
|
||||
@@ -87,6 +87,28 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Service started at -->
|
||||
<div v-if="systemInfo?.started_at" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('system.startedAtLabel') }}</label>
|
||||
<p class="desc">{{ $t('system.startedAtDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ formatStartedAt(systemInfo.started_at) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Service uptime -->
|
||||
<div v-if="displayUptimeSeconds != null" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('system.uptimeLabel') }}</label>
|
||||
<p class="desc">{{ $t('system.uptimeDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<span class="info-value">{{ formatUptime(displayUptimeSeconds) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DB Version -->
|
||||
<div v-if="systemInfo?.db_version || systemInfo?.db_migration_error" class="setting-row">
|
||||
<div class="setting-info">
|
||||
@@ -170,11 +192,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { getSystemInfo, type SystemInfo } from '@/api/system'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
const { t, locale } = useI18n()
|
||||
|
||||
// Reactive state
|
||||
const systemInfo = ref<SystemInfo | null>(null)
|
||||
@@ -182,6 +204,43 @@ const loading = ref(true)
|
||||
const error = ref('')
|
||||
const frontendVersion = __FRONTEND_VERSION__
|
||||
|
||||
let uptimeTicker: ReturnType<typeof setInterval> | null = null
|
||||
const uptimeTick = ref(0)
|
||||
|
||||
const displayUptimeSeconds = computed(() => {
|
||||
void uptimeTick.value
|
||||
const info = systemInfo.value
|
||||
if (info?.started_at) {
|
||||
const boot = new Date(info.started_at).getTime()
|
||||
if (!Number.isNaN(boot)) {
|
||||
return Math.floor((Date.now() - boot) / 1000)
|
||||
}
|
||||
}
|
||||
if (info?.uptime_seconds != null) return info.uptime_seconds
|
||||
return null
|
||||
})
|
||||
|
||||
function formatStartedAt(iso: string): string {
|
||||
const d = new Date(iso)
|
||||
if (Number.isNaN(d.getTime())) return iso
|
||||
return d.toLocaleString(locale.value)
|
||||
}
|
||||
|
||||
function formatUptime(totalSeconds: number): string {
|
||||
const sec = Math.max(0, Math.floor(totalSeconds))
|
||||
const days = Math.floor(sec / 86400)
|
||||
const hours = Math.floor((sec % 86400) / 3600)
|
||||
const minutes = Math.floor((sec % 3600) / 60)
|
||||
const seconds = sec % 60
|
||||
const parts: string[] = []
|
||||
if (days > 0) parts.push(t('system.uptimeDays', { n: days }))
|
||||
if (hours > 0 || days > 0) parts.push(t('system.uptimeHours', { n: hours }))
|
||||
if (minutes > 0 || hours > 0 || days > 0) parts.push(t('system.uptimeMinutes', { n: minutes }))
|
||||
if (parts.length === 0) return t('system.uptimeSeconds', { n: seconds })
|
||||
if (seconds > 0 && days === 0) parts.push(t('system.uptimeSeconds', { n: seconds }))
|
||||
return parts.join(' ')
|
||||
}
|
||||
|
||||
const troubleshootingDocsURL =
|
||||
'https://github.com/Tencent/WeKnora/blob/main/docs/migration-troubleshooting.md'
|
||||
|
||||
@@ -236,6 +295,16 @@ const loadInfo = async () => {
|
||||
// Lifecycle
|
||||
onMounted(() => {
|
||||
loadInfo()
|
||||
uptimeTicker = setInterval(() => {
|
||||
uptimeTick.value++
|
||||
}, 30_000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (uptimeTicker) {
|
||||
clearInterval(uptimeTicker)
|
||||
uptimeTicker = null
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user