Skip to content

Commit b666747

Browse files
authored
feat: guard null stats (#5800)
1 parent c1b0e4a commit b666747

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

packages/ui/src/layouts/wrapped/hosting/manage/components/ServerManageStats.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ const padGraph = (data: number[]) => {
104104
const cpuData = computed(() => padGraph(props.data?.graph.cpu ?? []))
105105
const ramData = computed(() => padGraph(props.data?.graph.ram ?? []))
106106
107-
const cpuPercent = computed(() => stats.value.cpu_percent)
108-
const ramPercent = computed(() => (stats.value.ram_usage_bytes / stats.value.ram_total_bytes) * 100)
107+
const cpuPercent = computed(() => stats.value.cpu_percent ?? 0)
108+
const ramPercent = computed(
109+
() => ((stats.value.ram_usage_bytes ?? 0) / (stats.value.ram_total_bytes || 1)) * 100,
110+
)
109111
110112
const cpuWarning = computed(() => cpuPercent.value >= 90)
111113
const ramWarning = computed(() => ramPercent.value >= 90)
@@ -167,7 +169,7 @@ const formatBytes = (bytes: number) => {
167169
const metrics = computed(() => {
168170
const storageMetric = {
169171
title: 'Storage',
170-
value: props.loading ? '0 B' : formatBytes(stats.value.storage_usage_bytes),
172+
value: props.loading ? '0 B' : formatBytes(stats.value.storage_usage_bytes ?? 0),
171173
icon: FolderOpenIcon,
172174
showGraph: false,
173175
chartOptions: null as ReturnType<typeof buildChartOptions> | null,
@@ -213,7 +215,7 @@ const metrics = computed(() => {
213215
title: 'Memory',
214216
value:
215217
props.showMemoryAsBytes || userPreferences.value.ramAsNumber
216-
? formatBytes(stats.value.ram_usage_bytes)
218+
? formatBytes(stats.value.ram_usage_bytes ?? 0)
217219
: `${ramPercent.value.toFixed(2)}%`,
218220
icon: DatabaseIcon,
219221
showGraph: true,

0 commit comments

Comments
 (0)