2026-05-28 12:00:20 +08:00
|
|
|
<template>
|
|
|
|
|
<Card
|
|
|
|
|
variant="default"
|
|
|
|
|
class="overflow-hidden"
|
|
|
|
|
>
|
2026-06-01 20:49:38 +08:00
|
|
|
<HealthMonitorHeader
|
|
|
|
|
v-model:lookback-hours="lookbackHours"
|
|
|
|
|
:title="title"
|
2026-06-02 00:10:59 +08:00
|
|
|
description="仅展示活跃提供商,点击详情查看该提供商关联的端点与模型健康"
|
2026-06-01 20:49:38 +08:00
|
|
|
: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
|
2026-06-02 00:10:59 +08:00
|
|
|
v-else-if="visibleProviders.length === 0"
|
2026-05-28 12:00:20 +08:00
|
|
|
class="flex flex-col items-center justify-center py-12 text-muted-foreground"
|
|
|
|
|
>
|
|
|
|
|
<Server class="w-12 h-12 mb-3 opacity-30" />
|
2026-06-02 00:10:59 +08:00
|
|
|
<p>暂无提供商健康数据</p>
|
2026-05-28 12:00:20 +08:00
|
|
|
<p class="text-xs mt-1">
|
2026-06-02 00:10:59 +08:00
|
|
|
当前没有提供商产生请求记录
|
2026-05-28 12:00:20 +08:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
v-else
|
2026-06-02 00:10:59 +08:00
|
|
|
class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4"
|
2026-05-28 12:00:20 +08:00
|
|
|
>
|
2026-06-02 00:10:59 +08:00
|
|
|
<div
|
|
|
|
|
v-for="provider in visibleProviders"
|
2026-05-28 12:00:20 +08:00
|
|
|
:key="provider.provider_id"
|
2026-06-02 00:10:59 +08:00
|
|
|
class="relative overflow-hidden rounded-xl border border-border/60 bg-card/60 p-4 transition-colors hover:border-primary/50"
|
2026-05-28 12:00:20 +08:00
|
|
|
>
|
2026-06-02 00:10:59 +08:00
|
|
|
<div class="absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-primary/40 to-transparent" />
|
|
|
|
|
<div class="flex items-start justify-between gap-3">
|
|
|
|
|
<div class="flex min-w-0 items-center gap-3">
|
|
|
|
|
<div class="flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-xl border border-border/60 bg-muted/50">
|
|
|
|
|
<Server class="h-5 w-5 text-muted-foreground" />
|
2026-05-28 12:00:20 +08:00
|
|
|
</div>
|
2026-06-02 00:10:59 +08:00
|
|
|
<div class="min-w-0">
|
|
|
|
|
<h4 class="truncate text-sm font-semibold">
|
|
|
|
|
{{ provider.provider_name }}
|
|
|
|
|
</h4>
|
2026-05-28 12:00:20 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-06-02 00:10:59 +08:00
|
|
|
<Badge
|
|
|
|
|
:variant="getHealthBadgeVariant(provider)"
|
|
|
|
|
class="shrink-0"
|
|
|
|
|
>
|
|
|
|
|
{{ getHealthLabel(provider) }}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<HealthMetricGrid
|
|
|
|
|
class="mt-4"
|
|
|
|
|
:avg-latency-ms="provider.avg_latency_ms"
|
|
|
|
|
:avg-first-byte-ms="provider.avg_first_byte_ms"
|
|
|
|
|
:avg-tps="provider.avg_tps"
|
|
|
|
|
:total-attempts="provider.total_attempts"
|
|
|
|
|
:success-rate="provider.success_rate"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div class="mt-4 flex items-center justify-between gap-3 text-[11px] uppercase tracking-wide text-muted-foreground">
|
|
|
|
|
<span>History (60pts)</span>
|
|
|
|
|
<span class="truncate normal-case tracking-normal">
|
|
|
|
|
{{ getProviderMetaText(provider) }}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<HealthStatusTimeline
|
|
|
|
|
class="mt-2"
|
|
|
|
|
:timeline="provider.timeline"
|
2026-06-02 10:36:54 +08:00
|
|
|
:timeline-details="provider.timeline_details"
|
2026-06-02 00:10:59 +08:00
|
|
|
:time-range-start="provider.time_range_start"
|
|
|
|
|
:time-range-end="provider.time_range_end"
|
|
|
|
|
:generated-at="generatedAt"
|
|
|
|
|
:lookback-hours="parseInt(lookbackHours)"
|
|
|
|
|
entity-label="提供商"
|
|
|
|
|
:entity-name="provider.provider_name"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div class="mt-4 flex justify-end">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="sm"
|
|
|
|
|
@click="openDetails(provider)"
|
|
|
|
|
>
|
|
|
|
|
查看详情
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-05-28 12:00:20 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-06-02 00:10:59 +08:00
|
|
|
import { computed, ref, onMounted, watch } from 'vue'
|
|
|
|
|
import { Loader2, Server } from 'lucide-vue-next'
|
2026-05-28 12:00:20 +08:00
|
|
|
import Card from '@/components/ui/card.vue'
|
|
|
|
|
import Badge from '@/components/ui/badge.vue'
|
2026-06-02 00:10:59 +08:00
|
|
|
import Button from '@/components/ui/button.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-05-28 12:00:20 +08:00
|
|
|
import { getProviderStatusMonitor } from '@/api/endpoints/health'
|
2026-06-01 20:49:38 +08:00
|
|
|
import type { ProviderStatusMonitor } from '@/api/endpoints/types'
|
2026-06-02 00:10:59 +08:00
|
|
|
import type { HealthMonitorDetailTarget, HealthMonitorSectionSummary } from './health-monitor-utils'
|
2026-05-28 12:00:20 +08:00
|
|
|
import { useToast } from '@/composables/useToast'
|
|
|
|
|
import { parseApiError } from '@/utils/errorParser'
|
2026-06-01 20:49:38 +08:00
|
|
|
import {
|
|
|
|
|
formatCompactNumber,
|
|
|
|
|
getHealthBadgeVariant,
|
2026-06-02 00:10:59 +08:00
|
|
|
getHealthLabel,
|
|
|
|
|
summarizeHealthMonitorItems
|
2026-06-01 20:49:38 +08:00
|
|
|
} from './health-monitor-utils'
|
2026-05-28 12:00:20 +08:00
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
|
title?: string
|
|
|
|
|
}>(), {
|
|
|
|
|
title: '提供商健康监控'
|
|
|
|
|
})
|
|
|
|
|
|
2026-06-02 00:10:59 +08:00
|
|
|
const emit = defineEmits<{
|
|
|
|
|
viewDetails: [target: HealthMonitorDetailTarget]
|
|
|
|
|
summaryUpdated: [summary: HealthMonitorSectionSummary]
|
|
|
|
|
}>()
|
|
|
|
|
|
2026-05-28 12:00:20 +08:00
|
|
|
const { error: showError } = useToast()
|
|
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
const loadingMonitors = ref(false)
|
|
|
|
|
const providers = ref<ProviderStatusMonitor[]>([])
|
|
|
|
|
const generatedAt = ref<string | null>(null)
|
|
|
|
|
const lookbackHours = ref('6')
|
2026-06-02 00:10:59 +08:00
|
|
|
const visibleProviders = computed(() => providers.value.filter(provider => provider.total_attempts > 0))
|
2026-05-28 12:00:20 +08:00
|
|
|
|
|
|
|
|
async function loadMonitors() {
|
|
|
|
|
loadingMonitors.value = true
|
|
|
|
|
try {
|
|
|
|
|
const data = await getProviderStatusMonitor({
|
|
|
|
|
lookback_hours: parseInt(lookbackHours.value),
|
|
|
|
|
provider_limit: 50,
|
|
|
|
|
per_provider_model_limit: 12,
|
|
|
|
|
per_model_limit: 100
|
|
|
|
|
})
|
|
|
|
|
providers.value = data.providers || []
|
|
|
|
|
generatedAt.value = data.generated_at || null
|
2026-06-02 00:10:59 +08:00
|
|
|
emitSummary()
|
2026-05-28 12:00:20 +08:00
|
|
|
} catch (err: unknown) {
|
|
|
|
|
showError(parseApiError(err, '加载提供商健康监控数据失败'), '错误')
|
|
|
|
|
} finally {
|
|
|
|
|
loadingMonitors.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function refreshData() {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
|
|
|
|
await loadMonitors()
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getProviderMetaText(provider: ProviderStatusMonitor) {
|
|
|
|
|
const attempts = `${formatCompactNumber(provider.total_attempts)} 次请求`
|
|
|
|
|
return `${provider.model_count} 个模型 / ${attempts}`
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 00:10:59 +08:00
|
|
|
function openDetails(provider: ProviderStatusMonitor) {
|
|
|
|
|
emit('viewDetails', {
|
|
|
|
|
lookbackHours: parseInt(lookbackHours.value),
|
|
|
|
|
source: {
|
|
|
|
|
kind: 'provider',
|
|
|
|
|
value: provider.provider_name,
|
|
|
|
|
title: provider.provider_name,
|
|
|
|
|
metaText: null,
|
|
|
|
|
totalAttempts: provider.total_attempts,
|
|
|
|
|
successCount: provider.success_count,
|
|
|
|
|
failedCount: provider.failed_count,
|
|
|
|
|
successRate: provider.success_rate,
|
|
|
|
|
avgLatencyMs: provider.avg_latency_ms,
|
|
|
|
|
avgFirstByteMs: provider.avg_first_byte_ms,
|
|
|
|
|
avgTps: provider.avg_tps,
|
|
|
|
|
timeline: provider.timeline || null,
|
2026-06-02 10:36:54 +08:00
|
|
|
timelineDetails: provider.timeline_details || null,
|
2026-06-02 00:10:59 +08:00
|
|
|
timeRangeStart: provider.time_range_start || null,
|
|
|
|
|
timeRangeEnd: provider.time_range_end || null
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function emitSummary() {
|
|
|
|
|
emit('summaryUpdated', summarizeHealthMonitorItems(visibleProviders.value))
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 12:00:20 +08:00
|
|
|
watch(lookbackHours, () => {
|
|
|
|
|
loadMonitors()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
refreshData()
|
|
|
|
|
})
|
|
|
|
|
</script>
|