2026-06-12 02:56:21 +08:00
|
|
|
|
<script setup lang="ts">
|
2026-06-12 03:47:56 +08:00
|
|
|
|
import { ref, computed } from 'vue'
|
2026-06-12 02:56:21 +08:00
|
|
|
|
import type { WatchSlot } from '@/composables/useWatchPins'
|
2026-06-12 04:04:48 +08:00
|
|
|
|
import { formatBytesPerSec, formatRemaining, probeStatusColor, probeStatusLabel, formatProbeError, isPsutilMissingError } from '@/utils/watchFormat'
|
2026-06-12 02:56:21 +08:00
|
|
|
|
import WatchSparkline from '@/components/watch/WatchSparkline.vue'
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
slot: WatchSlot
|
2026-06-12 04:04:48 +08:00
|
|
|
|
psutilInstallLoading?: boolean
|
2026-06-12 02:56:21 +08:00
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
remove: [slotIndex: number]
|
|
|
|
|
|
processes: [slot: WatchSlot]
|
|
|
|
|
|
history: [slot: WatchSlot]
|
2026-06-12 03:07:00 +08:00
|
|
|
|
pick: [slotIndex: number]
|
2026-06-12 03:47:56 +08:00
|
|
|
|
monitoring: [slotIndex: number, enabled: boolean]
|
|
|
|
|
|
ttl: [slotIndex: number, hours: 8 | 24]
|
2026-06-12 04:04:48 +08:00
|
|
|
|
installPsutil: [slotIndex: number]
|
2026-06-12 02:56:21 +08:00
|
|
|
|
}>()
|
|
|
|
|
|
|
2026-06-12 03:47:56 +08:00
|
|
|
|
const monitoringOn = computed(() => props.slot.monitoring_enabled !== false)
|
|
|
|
|
|
const slotTtl = computed(() => (props.slot.ttl_hours === 24 ? 24 : 8) as 8 | 24)
|
2026-06-12 04:04:48 +08:00
|
|
|
|
const showPsutilInstall = computed(() =>
|
|
|
|
|
|
monitoringOn.value && isPsutilMissingError(props.slot.metrics?.error, props.slot.metrics?.probe_status),
|
|
|
|
|
|
)
|
2026-06-12 03:47:56 +08:00
|
|
|
|
|
2026-06-12 02:56:21 +08:00
|
|
|
|
const chartMetric = ref<'cpu_pct' | 'mem_pct' | 'disk_pct'>('cpu_pct')
|
|
|
|
|
|
|
|
|
|
|
|
function pct(v: number | null | undefined) {
|
|
|
|
|
|
return v != null ? `${v}%` : '—'
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<v-card
|
|
|
|
|
|
v-if="!slot.empty"
|
|
|
|
|
|
elevation="0"
|
|
|
|
|
|
border
|
|
|
|
|
|
rounded="lg"
|
2026-06-12 03:07:00 +08:00
|
|
|
|
class="watch-slot-card pa-3 watch-slot-card--filled"
|
2026-06-12 03:47:56 +08:00
|
|
|
|
:class="{
|
|
|
|
|
|
'watch-slot-card--error': monitoringOn && slot.metrics?.probe_status && slot.metrics.probe_status !== 'ok',
|
|
|
|
|
|
'watch-slot-card--paused': !monitoringOn,
|
|
|
|
|
|
}"
|
2026-06-12 03:07:00 +08:00
|
|
|
|
role="button"
|
|
|
|
|
|
tabindex="0"
|
|
|
|
|
|
@click="emit('history', slot)"
|
|
|
|
|
|
@keydown.enter.prevent="emit('history', slot)"
|
2026-06-12 02:56:21 +08:00
|
|
|
|
>
|
2026-06-12 03:07:00 +08:00
|
|
|
|
<div class="d-flex align-center mb-2" @click.stop>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
<div class="text-subtitle-2 text-truncate flex-grow-1" :title="slot.server_name">
|
|
|
|
|
|
{{ slot.server_name || `ID ${slot.server_id}` }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<v-chip size="x-small" variant="tonal" color="info" label>
|
|
|
|
|
|
槽 {{ slot.slot_index + 1 }}
|
|
|
|
|
|
</v-chip>
|
2026-06-12 03:47:56 +08:00
|
|
|
|
<v-switch
|
|
|
|
|
|
:model-value="monitoringOn"
|
|
|
|
|
|
density="compact"
|
|
|
|
|
|
hide-details
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
class="watch-slot-switch ml-1"
|
|
|
|
|
|
@click.stop
|
|
|
|
|
|
@update:model-value="emit('monitoring', slot.slot_index, $event ?? false)"
|
|
|
|
|
|
/>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
<v-btn icon="mdi-close" size="x-small" variant="text" @click="emit('remove', slot.slot_index)" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-06-12 03:47:56 +08:00
|
|
|
|
<div class="d-flex align-center mb-2 ga-1" @click.stop>
|
|
|
|
|
|
<span class="text-caption text-medium-emphasis mr-1">时长</span>
|
|
|
|
|
|
<v-btn-toggle
|
|
|
|
|
|
:model-value="slotTtl"
|
|
|
|
|
|
density="compact"
|
|
|
|
|
|
variant="outlined"
|
|
|
|
|
|
divided
|
|
|
|
|
|
mandatory
|
|
|
|
|
|
@update:model-value="emit('ttl', slot.slot_index, ($event ?? 8) as 8 | 24)"
|
|
|
|
|
|
>
|
|
|
|
|
|
<v-btn :value="8" size="x-small">8h</v-btn>
|
|
|
|
|
|
<v-btn :value="24" size="x-small">24h</v-btn>
|
|
|
|
|
|
</v-btn-toggle>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-if="!monitoringOn" class="text-caption text-medium-emphasis mb-2" @click.stop>
|
|
|
|
|
|
实时监测已关闭 · 槽位保留 · Agent 恢复 60s 智能上报
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<template v-if="monitoringOn">
|
2026-06-12 03:07:00 +08:00
|
|
|
|
<div @click.stop>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
<v-chip
|
|
|
|
|
|
v-if="slot.metrics?.probe_status"
|
|
|
|
|
|
size="x-small"
|
|
|
|
|
|
:color="probeStatusColor(slot.metrics.probe_status)"
|
|
|
|
|
|
variant="tonal"
|
|
|
|
|
|
class="mb-2"
|
|
|
|
|
|
label
|
|
|
|
|
|
>
|
2026-06-12 03:47:56 +08:00
|
|
|
|
{{ probeStatusLabel(slot.metrics.probe_status) }}
|
2026-06-12 02:56:21 +08:00
|
|
|
|
</v-chip>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="d-flex justify-space-between text-caption mb-1">
|
|
|
|
|
|
<span>CPU {{ pct(slot.metrics?.cpu_pct) }}</span>
|
|
|
|
|
|
<span>MEM {{ pct(slot.metrics?.mem_pct) }}</span>
|
|
|
|
|
|
<span>DISK {{ pct(slot.metrics?.disk_pct) }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="text-caption text-medium-emphasis mb-1">
|
|
|
|
|
|
↑ {{ formatBytesPerSec(slot.metrics?.net_up_bps) }}
|
|
|
|
|
|
· ↓ {{ formatBytesPerSec(slot.metrics?.net_down_bps) }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="text-caption text-medium-emphasis mb-2">
|
|
|
|
|
|
读 {{ formatBytesPerSec(slot.metrics?.disk_read_bps) }}
|
|
|
|
|
|
· 写 {{ formatBytesPerSec(slot.metrics?.disk_write_bps) }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<v-btn-toggle v-model="chartMetric" density="compact" variant="outlined" divided class="mb-1">
|
|
|
|
|
|
<v-btn value="cpu_pct" size="x-small">CPU</v-btn>
|
|
|
|
|
|
<v-btn value="mem_pct" size="x-small">MEM</v-btn>
|
|
|
|
|
|
<v-btn value="disk_pct" size="x-small">DISK</v-btn>
|
|
|
|
|
|
</v-btn-toggle>
|
|
|
|
|
|
|
|
|
|
|
|
<WatchSparkline :points="slot.sparkline || []" :metric="chartMetric" />
|
|
|
|
|
|
|
2026-06-12 03:47:56 +08:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="slot.metrics?.error"
|
2026-06-12 04:04:48 +08:00
|
|
|
|
class="text-caption text-error mt-1"
|
2026-06-12 03:47:56 +08:00
|
|
|
|
:title="formatProbeError(slot.metrics.error, slot.metrics.probe_status)"
|
|
|
|
|
|
>
|
2026-06-12 04:04:48 +08:00
|
|
|
|
<div class="text-truncate">
|
|
|
|
|
|
{{ formatProbeError(slot.metrics.error, slot.metrics.probe_status) }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<v-btn
|
|
|
|
|
|
v-if="showPsutilInstall"
|
|
|
|
|
|
size="x-small"
|
|
|
|
|
|
variant="tonal"
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
class="mt-1"
|
|
|
|
|
|
:loading="props.psutilInstallLoading"
|
|
|
|
|
|
@click.stop="emit('installPsutil', slot.slot_index)"
|
|
|
|
|
|
>
|
|
|
|
|
|
安装 psutil(SSH)
|
|
|
|
|
|
</v-btn>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="d-flex align-center justify-space-between mt-2">
|
2026-06-12 03:47:56 +08:00
|
|
|
|
<span class="text-caption text-medium-emphasis">
|
|
|
|
|
|
剩余 {{ formatRemaining(slot.remaining_sec) }} · {{ slotTtl }}h
|
|
|
|
|
|
</span>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
<div class="d-flex ga-1">
|
2026-06-12 03:07:00 +08:00
|
|
|
|
<v-btn size="x-small" variant="text" @click.stop="emit('processes', slot)">进程</v-btn>
|
|
|
|
|
|
<v-btn size="x-small" variant="text" @click.stop="emit('history', slot)">历史</v-btn>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-06-12 03:07:00 +08:00
|
|
|
|
</div>
|
2026-06-12 03:47:56 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<div v-else class="d-flex align-center justify-space-between mt-2" @click.stop>
|
|
|
|
|
|
<span class="text-caption text-medium-emphasis">已暂停 · {{ slotTtl }}h</span>
|
|
|
|
|
|
<div class="d-flex ga-1">
|
|
|
|
|
|
<v-btn size="x-small" variant="text" @click.stop="emit('history', slot)">历史</v-btn>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
</v-card>
|
|
|
|
|
|
|
|
|
|
|
|
<v-card
|
|
|
|
|
|
v-else
|
|
|
|
|
|
elevation="0"
|
|
|
|
|
|
border
|
|
|
|
|
|
rounded="lg"
|
|
|
|
|
|
class="watch-slot-card watch-slot-card--empty d-flex align-center justify-center pa-4"
|
|
|
|
|
|
variant="outlined"
|
2026-06-12 03:07:00 +08:00
|
|
|
|
role="button"
|
|
|
|
|
|
tabindex="0"
|
|
|
|
|
|
@click="emit('pick', slot.slot_index)"
|
|
|
|
|
|
@keydown.enter.prevent="emit('pick', slot.slot_index)"
|
2026-06-12 02:56:21 +08:00
|
|
|
|
>
|
|
|
|
|
|
<div class="text-center text-medium-emphasis">
|
|
|
|
|
|
<v-icon size="28" class="mb-1">mdi-plus-circle-outline</v-icon>
|
2026-06-12 03:07:00 +08:00
|
|
|
|
<div class="text-caption">槽 {{ slot.slot_index + 1 }} · 添加监测</div>
|
2026-06-12 02:56:21 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</v-card>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.watch-slot-card {
|
|
|
|
|
|
min-height: 220px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.watch-slot-card--empty {
|
|
|
|
|
|
min-height: 220px;
|
|
|
|
|
|
border-style: dashed !important;
|
2026-06-12 03:07:00 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: background-color 0.15s ease;
|
|
|
|
|
|
}
|
|
|
|
|
|
.watch-slot-card--empty:hover {
|
|
|
|
|
|
background: rgba(var(--v-theme-primary), 0.04);
|
|
|
|
|
|
}
|
|
|
|
|
|
.watch-slot-card--filled {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
.watch-slot-card--filled:hover {
|
|
|
|
|
|
background: rgba(var(--v-theme-surface-variant), 0.3);
|
2026-06-12 02:56:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
.watch-slot-card--error {
|
|
|
|
|
|
border-color: rgb(var(--v-theme-error)) !important;
|
|
|
|
|
|
}
|
2026-06-12 03:47:56 +08:00
|
|
|
|
.watch-slot-card--paused {
|
|
|
|
|
|
opacity: 0.72;
|
|
|
|
|
|
background: rgba(var(--v-theme-surface-variant), 0.15);
|
|
|
|
|
|
}
|
|
|
|
|
|
.watch-slot-switch {
|
|
|
|
|
|
flex: 0 0 auto;
|
|
|
|
|
|
transform: scale(0.85);
|
|
|
|
|
|
}
|
2026-06-12 02:56:21 +08:00
|
|
|
|
</style>
|