Skip to content

Commit 6eae160

Browse files
committed
feat(metrics): enhance metrics handling with reconnect logic and history caching
1 parent 7335c21 commit 6eae160

6 files changed

Lines changed: 327 additions & 186 deletions

File tree

app.vue

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
<script setup>
2-
import { useLocalStorage } from '@vueuse/core'
32
import { useProcessesStore } from "~/stores/processes.js";
43
import { useLogsStore } from "~/stores/logs.js";
54
import { useMetricsStore } from "~/stores/metrics.js";
65
76
const processesStore = useProcessesStore()
87
const logsStore = useLogsStore()
98
const metricsStore = useMetricsStore()
10-
const cpuWarnThreshold = useLocalStorage('metrics.cpuWarnThreshold', 85)
11-
const memWarnThreshold = useLocalStorage('metrics.memWarnThreshold', 85)
12-
const diskWarnThreshold = useLocalStorage('metrics.diskWarnThreshold', 90)
13-
14-
const globalAlerts = computed(() => {
15-
const snapshot = metricsStore.latestSnapshot
16-
if (!snapshot?.system) return []
17-
const list = []
18-
if (snapshot.system.cpu_percent != null && snapshot.system.cpu_percent >= cpuWarnThreshold.value) {
19-
list.push(`CPU ${snapshot.system.cpu_percent.toFixed(1)}%`)
20-
}
21-
if (snapshot.system.mem?.percent != null && snapshot.system.mem.percent >= memWarnThreshold.value) {
22-
list.push(`Memory ${snapshot.system.mem.percent.toFixed(1)}%`)
23-
}
24-
if (snapshot.system.disk?.percent != null && snapshot.system.disk.percent >= diskWarnThreshold.value) {
25-
list.push(`Disk ${snapshot.system.disk.percent.toFixed(1)}%`)
26-
}
27-
return list
28-
})
299
3010
3111
onMounted(async () => {
@@ -43,10 +23,6 @@ watchEffect(() => {
4323

4424
<template>
4525
<NuxtLayout>
46-
<div v-if="globalAlerts.length" class="mx-4 md:mx-8 mt-3 mb-2 rounded border border-amber-600/50 bg-amber-500/10 px-3 py-2 text-xs text-amber-200">
47-
<span class="font-semibold">System alerts:</span>
48-
<span class="ml-2">{{ globalAlerts.join(' · ') }}</span>
49-
</div>
5026
<NuxtPage />
5127
</NuxtLayout>
5228
</template>

layouts/default.vue

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup>
22
import { ref, computed } from 'vue'
33
import { useRoute } from 'vue-router'
4+
import { useLocalStorage } from '@vueuse/core'
5+
import { useMetricsStore } from "~/stores/metrics.js"
46
57
const sideBar = ref(true)
68
const toggleSideBar = (value) => { sideBar.value = value ?? !sideBar.value }
@@ -10,6 +12,27 @@ const route = useRoute()
1012
1113
// only show sidebar when *not* on the onboarding page
1214
const showSidebar = computed(() => !route.path.startsWith('/onboarding'))
15+
16+
const metricsStore = useMetricsStore()
17+
const cpuWarnThreshold = useLocalStorage('metrics.cpuWarnThreshold', 85)
18+
const memWarnThreshold = useLocalStorage('metrics.memWarnThreshold', 85)
19+
const diskWarnThreshold = useLocalStorage('metrics.diskWarnThreshold', 90)
20+
21+
const globalAlerts = computed(() => {
22+
const snapshot = metricsStore.latestSnapshot
23+
if (!snapshot?.system) return []
24+
const list = []
25+
if (snapshot.system.cpu_percent != null && snapshot.system.cpu_percent >= cpuWarnThreshold.value) {
26+
list.push(`CPU ${snapshot.system.cpu_percent.toFixed(1)}%`)
27+
}
28+
if (snapshot.system.mem?.percent != null && snapshot.system.mem.percent >= memWarnThreshold.value) {
29+
list.push(`Memory ${snapshot.system.mem.percent.toFixed(1)}%`)
30+
}
31+
if (snapshot.system.disk?.percent != null && snapshot.system.disk.percent >= diskWarnThreshold.value) {
32+
list.push(`Disk ${snapshot.system.disk.percent.toFixed(1)}%`)
33+
}
34+
return list
35+
})
1336
</script>
1437
1538
<template>
@@ -32,8 +55,16 @@ const showSidebar = computed(() => !route.path.startsWith('/onboarding'))
3255
</div>
3356
3457
<!-- Main Content -->
35-
<div class="flex-1 overflow-auto">
36-
<slot />
58+
<div class="flex-1 min-h-0 flex flex-col">
59+
<div v-if="globalAlerts.length" class="px-4 md:px-8 pt-2">
60+
<div class="rounded border border-amber-600/50 bg-amber-500/10 px-3 py-2 text-xs text-amber-200">
61+
<span class="font-semibold">System alerts:</span>
62+
<span class="ml-2">{{ globalAlerts.join(' · ') }}</span>
63+
</div>
64+
</div>
65+
<div class="flex-1 min-h-0 overflow-y-auto overflow-x-hidden">
66+
<slot />
67+
</div>
3768
</div>
3869
</div>
3970
</div>

pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const enabledProcesses = computed(() => processesStore.enabledProcesses)
55
</script>
66

77
<template>
8-
<div class="relative h-full text-white overflow-auto bg-gray-900 flex flex-col gap-8 px-4 py-4 md:px-8">
8+
<div class="relative min-h-full text-white overflow-x-hidden bg-gray-900 flex flex-col gap-8 px-4 py-4 md:px-8">
99
<InfoBar />
1010

1111
<h1 class="text-4xl font-bold">Service Dashboard</h1>

0 commit comments

Comments
 (0)