2026-05-28 12:00:20 +08:00
|
|
|
<template>
|
2026-06-01 18:34:51 +08:00
|
|
|
<Card variant="default" class="overflow-hidden">
|
2026-06-01 20:49:38 +08:00
|
|
|
<HealthMonitorHeader
|
|
|
|
|
v-model:lookback-hours="lookbackHours"
|
|
|
|
|
:title="title"
|
|
|
|
|
description="基于真实请求统计模型可用率、平均耗时、平均TTFB 与平均速度"
|
|
|
|
|
:loading="loading"
|
|
|
|
|
@refresh="refreshData"
|
|
|
|
|
/>
|
2026-05-28 12:00:20 +08:00
|
|
|
|
|
|
|
|
<div class="p-6">
|
|
|
|
|
<div
|
|
|
|
|
v-if="loadingMonitors"
|
|
|
|
|
class="flex items-center justify-center py-12"
|
|
|
|
|
>
|
|
|
|
|
<Loader2 class="w-6 h-6 animate-spin text-muted-foreground" />
|
|
|
|
|
<span class="ml-2 text-muted-foreground">加载中...</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
v-else-if="monitors.length === 0"
|
|
|
|
|
class="flex flex-col items-center justify-center py-12 text-muted-foreground"
|
|
|
|
|
>
|
|
|
|
|
<Bot class="w-12 h-12 mb-3 opacity-30" />
|
|
|
|
|
<p>暂无模型健康监控数据</p>
|
2026-06-01 18:34:51 +08:00
|
|
|
<p class="text-xs mt-1">模型尚未产生请求记录</p>
|
2026-05-28 12:00:20 +08:00
|
|
|
</div>
|
|
|
|
|
|
2026-06-01 18:34:51 +08:00
|
|
|
<div v-else class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
|
2026-05-28 12:00:20 +08:00
|
|
|
<div
|
|
|
|
|
v-for="monitor in monitors"
|
|
|
|
|
:key="monitor.model"
|
|
|
|
|
class="relative overflow-hidden rounded-xl border border-border/60 bg-card/60 p-4 transition-colors hover:border-primary/50"
|
|
|
|
|
>
|
2026-06-01 18:34:51 +08:00
|
|
|
<div
|
|
|
|
|
class="absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-primary/40 to-transparent"
|
|
|
|
|
/>
|
2026-05-28 12:00:20 +08:00
|
|
|
<div class="flex items-start justify-between gap-3">
|
|
|
|
|
<div class="flex min-w-0 items-center gap-3">
|
2026-06-01 18:34:51 +08:00
|
|
|
<div
|
|
|
|
|
class="flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-xl border border-border/60 bg-muted/50"
|
|
|
|
|
>
|
2026-05-28 12:00:20 +08:00
|
|
|
<Bot class="h-5 w-5 text-muted-foreground" />
|
|
|
|
|
</div>
|
|
|
|
|
<h4 class="min-w-0 truncate text-sm font-semibold">
|
|
|
|
|
{{ monitor.display_name || monitor.model }}
|
|
|
|
|
</h4>
|
|
|
|
|
</div>
|
2026-06-01 18:34:51 +08:00
|
|
|
<Badge :variant="getHealthBadgeVariant(monitor)" class="shrink-0">
|
2026-05-28 12:00:20 +08:00
|
|
|
{{ getHealthLabel(monitor) }}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-01 20:49:38 +08:00
|
|
|
<HealthMetricGrid
|
|
|
|
|
class="mt-4"
|
|
|
|
|
:avg-latency-ms="monitor.avg_latency_ms"
|
|
|
|
|
:avg-first-byte-ms="monitor.avg_first_byte_ms"
|
|
|
|
|
:avg-tps="monitor.avg_tps"
|
|
|
|
|
:total-attempts="monitor.total_attempts"
|
|
|
|
|
:success-rate="monitor.success_rate"
|
|
|
|
|
/>
|
2026-05-28 12:00:20 +08:00
|
|
|
|
2026-06-01 18:34:51 +08:00
|
|
|
<div
|
|
|
|
|
class="mt-4 flex items-center justify-between gap-3 text-[11px] uppercase tracking-wide text-muted-foreground"
|
|
|
|
|
>
|
2026-05-28 12:00:20 +08:00
|
|
|
<span>History (60pts)</span>
|
|
|
|
|
<span class="truncate normal-case tracking-normal">
|
|
|
|
|
{{ getModelMetaText(monitor) }}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-01 20:49:38 +08:00
|
|
|
<HealthStatusTimeline
|
|
|
|
|
class="mt-2"
|
|
|
|
|
:timeline="monitor.timeline"
|
|
|
|
|
:time-range-start="monitor.time_range_start"
|
|
|
|
|
:time-range-end="monitor.time_range_end"
|
|
|
|
|
:generated-at="generatedAt"
|
|
|
|
|
:lookback-hours="parseInt(lookbackHours)"
|
|
|
|
|
entity-label="模型"
|
|
|
|
|
:entity-name="monitor.model"
|
|
|
|
|
/>
|
2026-05-28 12:00:20 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-06-01 18:34:51 +08:00
|
|
|
import { ref, onMounted, watch } from "vue";
|
2026-06-01 20:49:38 +08:00
|
|
|
import { Bot, Loader2 } from "lucide-vue-next";
|
2026-06-01 18:34:51 +08:00
|
|
|
import Card from "@/components/ui/card.vue";
|
|
|
|
|
import Badge from "@/components/ui/badge.vue";
|
2026-06-01 20:49:38 +08:00
|
|
|
import HealthMetricGrid from "./HealthMetricGrid.vue";
|
|
|
|
|
import HealthMonitorHeader from "./HealthMonitorHeader.vue";
|
|
|
|
|
import HealthStatusTimeline from "./HealthStatusTimeline.vue";
|
2026-06-01 18:34:51 +08:00
|
|
|
import {
|
|
|
|
|
getModelStatusMonitor,
|
|
|
|
|
getPublicModelStatusMonitor,
|
|
|
|
|
} from "@/api/endpoints/health";
|
|
|
|
|
import type { ModelStatusMonitor } from "@/api/endpoints/types";
|
|
|
|
|
import { useToast } from "@/composables/useToast";
|
|
|
|
|
import { parseApiError } from "@/utils/errorParser";
|
2026-06-01 20:49:38 +08:00
|
|
|
import {
|
|
|
|
|
formatCompactNumber,
|
|
|
|
|
getHealthBadgeVariant,
|
|
|
|
|
getHealthLabel,
|
|
|
|
|
} from "./health-monitor-utils";
|
2026-05-28 12:00:20 +08:00
|
|
|
|
2026-06-01 18:34:51 +08:00
|
|
|
const props = withDefaults(
|
|
|
|
|
defineProps<{
|
|
|
|
|
title?: string;
|
|
|
|
|
isAdmin?: boolean;
|
|
|
|
|
showProviderInfo?: boolean;
|
|
|
|
|
}>(),
|
|
|
|
|
{
|
|
|
|
|
title: "模型健康监控",
|
|
|
|
|
isAdmin: false,
|
|
|
|
|
showProviderInfo: false,
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-05-28 12:00:20 +08:00
|
|
|
|
2026-06-01 18:34:51 +08:00
|
|
|
const { error: showError } = useToast();
|
2026-05-28 12:00:20 +08:00
|
|
|
|
2026-06-01 18:34:51 +08:00
|
|
|
const loading = ref(false);
|
|
|
|
|
const loadingMonitors = ref(false);
|
|
|
|
|
const monitors = ref<ModelStatusMonitor[]>([]);
|
|
|
|
|
const generatedAt = ref<string | null>(null);
|
|
|
|
|
const lookbackHours = ref("6");
|
2026-05-28 12:00:20 +08:00
|
|
|
|
|
|
|
|
async function loadMonitors() {
|
2026-06-01 18:34:51 +08:00
|
|
|
loadingMonitors.value = true;
|
2026-05-28 12:00:20 +08:00
|
|
|
try {
|
|
|
|
|
const params = {
|
|
|
|
|
lookback_hours: parseInt(lookbackHours.value),
|
|
|
|
|
model_limit: 12,
|
2026-06-01 18:34:51 +08:00
|
|
|
per_model_limit: 100,
|
|
|
|
|
};
|
2026-05-28 12:00:20 +08:00
|
|
|
|
|
|
|
|
const data = props.isAdmin
|
|
|
|
|
? await getModelStatusMonitor(params)
|
2026-06-01 18:34:51 +08:00
|
|
|
: await getPublicModelStatusMonitor(params);
|
|
|
|
|
monitors.value = data.models || [];
|
|
|
|
|
generatedAt.value = data.generated_at || null;
|
2026-05-28 12:00:20 +08:00
|
|
|
} catch (err: unknown) {
|
2026-06-01 18:34:51 +08:00
|
|
|
showError(parseApiError(err, "加载模型健康监控数据失败"), "错误");
|
2026-05-28 12:00:20 +08:00
|
|
|
} finally {
|
2026-06-01 18:34:51 +08:00
|
|
|
loadingMonitors.value = false;
|
2026-05-28 12:00:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function refreshData() {
|
2026-06-01 18:34:51 +08:00
|
|
|
loading.value = true;
|
2026-05-28 12:00:20 +08:00
|
|
|
try {
|
2026-06-01 18:34:51 +08:00
|
|
|
await loadMonitors();
|
2026-05-28 12:00:20 +08:00
|
|
|
} finally {
|
2026-06-01 18:34:51 +08:00
|
|
|
loading.value = false;
|
2026-05-28 12:00:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getModelMetaText(monitor: ModelStatusMonitor) {
|
2026-06-01 18:34:51 +08:00
|
|
|
const attempts = `${formatCompactNumber(monitor.total_attempts)} 次请求`;
|
|
|
|
|
if (props.showProviderInfo && typeof monitor.provider_count === "number") {
|
|
|
|
|
return `${monitor.provider_count} 个提供商 / ${attempts}`;
|
2026-05-28 12:00:20 +08:00
|
|
|
}
|
2026-06-01 18:34:51 +08:00
|
|
|
return attempts;
|
2026-05-28 12:00:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(lookbackHours, () => {
|
2026-06-01 18:34:51 +08:00
|
|
|
loadMonitors();
|
|
|
|
|
});
|
2026-05-28 12:00:20 +08:00
|
|
|
|
|
|
|
|
onMounted(() => {
|
2026-06-01 18:34:51 +08:00
|
|
|
refreshData();
|
|
|
|
|
});
|
2026-05-28 12:00:20 +08:00
|
|
|
</script>
|