2025-12-10 20:52:44 +08:00
|
|
|
<template>
|
2025-12-12 16:15:36 +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"
|
|
|
|
|
/>
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
|
|
|
<div class="p-6">
|
2025-12-12 16:15:36 +08:00
|
|
|
<div
|
|
|
|
|
v-if="loadingMonitors"
|
|
|
|
|
class="flex items-center justify-center py-12"
|
|
|
|
|
>
|
2025-12-10 20:52:44 +08:00
|
|
|
<Loader2 class="w-6 h-6 animate-spin text-muted-foreground" />
|
|
|
|
|
<span class="ml-2 text-muted-foreground">加载中...</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-12-12 16:15:36 +08:00
|
|
|
<div
|
2026-06-01 21:24:20 +08:00
|
|
|
v-else-if="visibleMonitors.length === 0"
|
2025-12-12 16:15:36 +08:00
|
|
|
class="flex flex-col items-center justify-center py-12 text-muted-foreground"
|
|
|
|
|
>
|
2025-12-10 20:52:44 +08:00
|
|
|
<Activity class="w-12 h-12 mb-3 opacity-30" />
|
|
|
|
|
<p>暂无健康监控数据</p>
|
2025-12-12 16:15:36 +08:00
|
|
|
<p class="text-xs mt-1">
|
|
|
|
|
端点尚未产生请求记录
|
|
|
|
|
</p>
|
2025-12-10 20:52:44 +08:00
|
|
|
</div>
|
|
|
|
|
|
2025-12-12 16:15:36 +08:00
|
|
|
<div
|
|
|
|
|
v-else
|
2026-06-01 20:49:38 +08:00
|
|
|
class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4"
|
2025-12-12 16:15:36 +08:00
|
|
|
>
|
2025-12-10 20:52:44 +08:00
|
|
|
<div
|
2026-06-01 21:24:20 +08:00
|
|
|
v-for="(monitor, index) in visibleMonitors"
|
2026-06-01 20:49:38 +08:00
|
|
|
:key="`${monitor.api_format}-${index}`"
|
|
|
|
|
class="relative overflow-hidden rounded-xl border border-border/60 bg-card/60 p-4 transition-colors hover:border-primary/50"
|
2025-12-10 20:52:44 +08:00
|
|
|
>
|
2026-06-01 20:49:38 +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"
|
|
|
|
|
>
|
|
|
|
|
<Activity class="h-5 w-5 text-muted-foreground" />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="min-w-0">
|
|
|
|
|
<h4 class="truncate text-sm font-semibold">
|
|
|
|
|
{{ formatApiFormat(monitor.api_format) }}
|
|
|
|
|
</h4>
|
2025-12-10 20:52:44 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-06-01 20:49:38 +08:00
|
|
|
<Badge
|
|
|
|
|
:variant="getHealthBadgeVariant(monitor)"
|
|
|
|
|
class="shrink-0"
|
|
|
|
|
>
|
|
|
|
|
{{ getHealthLabel(monitor) }}
|
|
|
|
|
</Badge>
|
|
|
|
|
</div>
|
2025-12-10 20:52:44 +08:00
|
|
|
|
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"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<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">
|
|
|
|
|
{{ getEndpointMetaText(monitor) }}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="mt-2">
|
|
|
|
|
<EndpointHealthTimeline
|
|
|
|
|
:monitor="monitor"
|
|
|
|
|
:lookback-hours="parseInt(lookbackHours)"
|
|
|
|
|
/>
|
2025-12-10 20:52:44 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-06-01 21:24:20 +08:00
|
|
|
import { computed, ref, onMounted, watch } from 'vue'
|
2025-12-10 20:52:44 +08:00
|
|
|
import { Activity, Loader2 } from 'lucide-vue-next'
|
|
|
|
|
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'
|
2025-12-10 20:52:44 +08:00
|
|
|
import EndpointHealthTimeline from './EndpointHealthTimeline.vue'
|
|
|
|
|
import { getEndpointStatusMonitor, getPublicEndpointStatusMonitor } from '@/api/endpoints/health'
|
|
|
|
|
import type { EndpointStatusMonitor, PublicEndpointStatusMonitor } from '@/api/endpoints/types'
|
|
|
|
|
import { useToast } from '@/composables/useToast'
|
2026-02-22 00:43:41 +08:00
|
|
|
import { parseApiError } from '@/utils/errorParser'
|
2026-02-19 14:51:08 +08:00
|
|
|
import { formatApiFormat } from '@/api/endpoints/types/api-format'
|
2026-06-01 20:49:38 +08:00
|
|
|
import {
|
|
|
|
|
formatCompactNumber,
|
|
|
|
|
getHealthBadgeVariant,
|
|
|
|
|
getHealthLabel
|
|
|
|
|
} from './health-monitor-utils'
|
|
|
|
|
|
|
|
|
|
type EndpointMonitor = EndpointStatusMonitor | PublicEndpointStatusMonitor
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
|
title?: string
|
|
|
|
|
isAdmin?: boolean
|
|
|
|
|
showProviderInfo?: boolean
|
|
|
|
|
}>(), {
|
|
|
|
|
title: '健康监控',
|
|
|
|
|
isAdmin: false,
|
|
|
|
|
showProviderInfo: false
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const { error: showError } = useToast()
|
|
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
const loadingMonitors = ref(false)
|
2026-06-01 20:49:38 +08:00
|
|
|
const monitors = ref<EndpointMonitor[]>([])
|
2025-12-10 20:52:44 +08:00
|
|
|
const lookbackHours = ref('6')
|
2026-06-01 21:24:20 +08:00
|
|
|
const visibleMonitors = computed(() => monitors.value.filter(monitor => monitor.total_attempts > 0))
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
|
|
|
async function loadMonitors() {
|
|
|
|
|
loadingMonitors.value = true
|
|
|
|
|
try {
|
|
|
|
|
const params = {
|
|
|
|
|
lookback_hours: parseInt(lookbackHours.value),
|
|
|
|
|
per_format_limit: 100
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (props.isAdmin) {
|
|
|
|
|
const data = await getEndpointStatusMonitor(params)
|
|
|
|
|
monitors.value = data.formats || []
|
|
|
|
|
} else {
|
|
|
|
|
const data = await getPublicEndpointStatusMonitor(params)
|
|
|
|
|
monitors.value = data.formats || []
|
|
|
|
|
}
|
2026-02-22 00:43:41 +08:00
|
|
|
} catch (err: unknown) {
|
|
|
|
|
showError(parseApiError(err, '加载健康监控数据失败'), '错误')
|
2025-12-10 20:52:44 +08:00
|
|
|
} finally {
|
|
|
|
|
loadingMonitors.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function refreshData() {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
|
|
|
|
await loadMonitors()
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-01 20:49:38 +08:00
|
|
|
function getEndpointMetaText(monitor: EndpointMonitor) {
|
|
|
|
|
const attempts = `${formatCompactNumber(monitor.total_attempts)} 次请求`
|
|
|
|
|
if (props.showProviderInfo && hasProviderInfo(monitor)) {
|
|
|
|
|
return `${monitor.provider_count} 个提供商 / ${monitor.key_count} 个密钥 / ${attempts}`
|
|
|
|
|
}
|
|
|
|
|
if (hasApiPath(monitor)) {
|
|
|
|
|
return `${monitor.api_path} / ${attempts}`
|
|
|
|
|
}
|
|
|
|
|
return attempts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasProviderInfo(monitor: EndpointMonitor): monitor is EndpointStatusMonitor {
|
|
|
|
|
return 'provider_count' in monitor && typeof monitor.provider_count === 'number'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasApiPath(monitor: EndpointMonitor): monitor is PublicEndpointStatusMonitor {
|
|
|
|
|
return 'api_path' in monitor && typeof monitor.api_path === 'string' && monitor.api_path.length > 0
|
2025-12-10 20:52:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(lookbackHours, () => {
|
|
|
|
|
loadMonitors()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
refreshData()
|
|
|
|
|
})
|
|
|
|
|
</script>
|