feat: localize performance monitoring
This commit is contained in:
1 parent
a069bb1bf1
commit
76c21b39b1
3 files changed
+45
-43
No files matched your search
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { Connection, RefreshRight, TopRight } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import * as echarts from 'echarts/core'
|
||||
@@ -60,12 +61,8 @@ interface PerformanceReport {
|
||||
databaseQueries: RankingItem[]
|
||||
}
|
||||
|
||||
const rangeOptions: { value: ReportRange; label: string }[] = [
|
||||
{ value: '15m', label: '15 分钟' },
|
||||
{ value: '1h', label: '1 小时' },
|
||||
{ value: '24h', label: '24 小时' },
|
||||
{ value: '7d', label: '7 天' },
|
||||
]
|
||||
const { locale, t } = useI18n()
|
||||
const rangeOptions = computed(() => (['15m', '1h', '24h', '7d'] as ReportRange[]).map(value => ({ value, label: t(`performance.ranges.${value}`) })))
|
||||
|
||||
const range = ref<ReportRange>('1h')
|
||||
const loading = ref(true)
|
||||
@@ -81,19 +78,19 @@ const hasSamples = computed(() =>
|
||||
|
||||
const operatingNote = computed(() => {
|
||||
const headline = report.value?.headline
|
||||
if (!headline) return '等待指标样本'
|
||||
if (!headline) return t('performance.notes.waiting')
|
||||
if ((headline.failedDatabaseCommandCount ?? 0) > 0)
|
||||
return '存在失败的数据库命令'
|
||||
return t('performance.notes.failedDatabase')
|
||||
if ((headline.serverErrorRatePercent ?? 0) >= 1)
|
||||
return '服务端错误率需要关注'
|
||||
return t('performance.notes.serverErrors')
|
||||
if ((headline.slowDatabaseCommandCount ?? 0) > 0)
|
||||
return '存在超过阈值的慢查询'
|
||||
return '当前采样窗口内未见明显异常'
|
||||
return t('performance.notes.slowQueries')
|
||||
return t('performance.notes.healthy')
|
||||
})
|
||||
|
||||
function formatNumber(value?: number, digits = 0) {
|
||||
if (value == null || !Number.isFinite(value)) return '—'
|
||||
return value.toLocaleString('zh-CN', {
|
||||
return value.toLocaleString(locale.value, {
|
||||
maximumFractionDigits: digits,
|
||||
minimumFractionDigits: digits,
|
||||
})
|
||||
@@ -101,7 +98,7 @@ function formatNumber(value?: number, digits = 0) {
|
||||
|
||||
function formatTime(value?: string) {
|
||||
if (!value) return '—'
|
||||
return new Date(value).toLocaleString('zh-CN', {
|
||||
return new Date(value).toLocaleString(locale.value, {
|
||||
hour12: false,
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
@@ -111,7 +108,7 @@ function formatTime(value?: string) {
|
||||
}
|
||||
|
||||
function formatAxisTime(value: string) {
|
||||
return new Date(value).toLocaleString('zh-CN', {
|
||||
return new Date(value).toLocaleString(locale.value, {
|
||||
hour12: false,
|
||||
month: range.value === '7d' ? '2-digit' : undefined,
|
||||
day: range.value === '7d' ? '2-digit' : undefined,
|
||||
@@ -198,7 +195,7 @@ function renderChart() {
|
||||
yAxis: [
|
||||
{
|
||||
type: 'value',
|
||||
name: '请求 / 秒',
|
||||
name: t('performance.requestsPerSecond'),
|
||||
nameTextStyle: { color: '#63727b', fontSize: 10 },
|
||||
splitLine: { lineStyle: { color: '#e8edef', type: 'dashed' } },
|
||||
axisLabel: { color: '#79878f', fontSize: 10 },
|
||||
@@ -213,7 +210,7 @@ function renderChart() {
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: '请求速率',
|
||||
name: t('performance.requestRate'),
|
||||
type: 'line',
|
||||
smooth: 0.22,
|
||||
symbol: 'none',
|
||||
@@ -224,7 +221,7 @@ function renderChart() {
|
||||
),
|
||||
},
|
||||
{
|
||||
name: '接口 P95',
|
||||
name: t('performance.endpointP95'),
|
||||
type: 'line',
|
||||
yAxisIndex: 1,
|
||||
smooth: 0.22,
|
||||
@@ -257,11 +254,10 @@ onUnmounted(disposeChart)
|
||||
<header class="performance-heading">
|
||||
<div>
|
||||
<span>PERFORMANCE RAIL / {{ report?.dataSource?.toUpperCase() || 'PROMETHEUS' }}</span>
|
||||
<h3 id="performance-title">系统性能</h3>
|
||||
<p>从接口进入数据库,定位响应时间消耗在哪里。</p>
|
||||
<h3 id="performance-title">{{ t('performance.title') }}</h3><p>{{ t('performance.description') }}</p>
|
||||
</div>
|
||||
<div class="performance-actions">
|
||||
<div class="range-switch" aria-label="性能报表时间范围">
|
||||
<div class="range-switch" :aria-label="t('performance.rangeAria')">
|
||||
<button
|
||||
v-for="item in rangeOptions"
|
||||
:key="item.value"
|
||||
@@ -277,7 +273,7 @@ onUnmounted(disposeChart)
|
||||
circle
|
||||
:icon="RefreshRight"
|
||||
:loading="loading"
|
||||
aria-label="刷新性能报表"
|
||||
:aria-label="t('performance.refreshAria')"
|
||||
@click="loadReport"
|
||||
/>
|
||||
</div>
|
||||
@@ -295,11 +291,11 @@ onUnmounted(disposeChart)
|
||||
<el-icon><Connection /></el-icon>
|
||||
<div>
|
||||
<strong>
|
||||
{{ report?.status === 'not_configured' ? '等待连接性能数据源' : '性能数据暂不可用' }}
|
||||
{{ t(report?.status === 'not_configured' ? 'performance.notConfigured' : 'performance.unavailable') }}
|
||||
</strong>
|
||||
<p>{{ report?.detail }}</p>
|
||||
<small>
|
||||
业务接口继续正常运行;报表不会回退读取教务业务数据库。
|
||||
{{ t('performance.fallbackNote') }}
|
||||
</small>
|
||||
</div>
|
||||
<a
|
||||
@@ -308,7 +304,7 @@ onUnmounted(disposeChart)
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
打开监控平台
|
||||
{{ t('performance.openDashboard') }}
|
||||
<el-icon><TopRight /></el-icon>
|
||||
</a>
|
||||
</div>
|
||||
@@ -316,7 +312,7 @@ onUnmounted(disposeChart)
|
||||
<template v-else>
|
||||
<div class="performance-strip">
|
||||
<div class="strip-lead">
|
||||
<span>采样结论</span>
|
||||
<span>{{ t('performance.sampleConclusion') }}</span>
|
||||
<strong>{{ operatingNote }}</strong>
|
||||
<small>
|
||||
{{ formatTime(report.from) }} — {{ formatTime(report.to) }}
|
||||
@@ -324,37 +320,37 @@ onUnmounted(disposeChart)
|
||||
</div>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>请求总量</dt>
|
||||
<dt>{{ t('performance.requestCount') }}</dt>
|
||||
<dd>{{ formatNumber(report.headline?.requestCount) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>接口 P95</dt>
|
||||
<dt>{{ t('performance.endpointP95') }}</dt>
|
||||
<dd>{{ formatNumber(report.headline?.requestP95Milliseconds, 1) }}<small>ms</small></dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>5xx 比例</dt>
|
||||
<dt>{{ t('performance.errorRate') }}</dt>
|
||||
<dd>{{ formatNumber(report.headline?.serverErrorRatePercent, 2) }}<small>%</small></dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>数据库 P95</dt>
|
||||
<dt>{{ t('performance.databaseP95') }}</dt>
|
||||
<dd>{{ formatNumber(report.headline?.databaseP95Milliseconds, 1) }}<small>ms</small></dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>慢查询</dt>
|
||||
<dt>{{ t('performance.slowQueries') }}</dt>
|
||||
<dd>{{ formatNumber(report.headline?.slowDatabaseCommandCount) }}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>查询失败</dt>
|
||||
<dt>{{ t('performance.queryFailures') }}</dt>
|
||||
<dd>{{ formatNumber(report.headline?.failedDatabaseCommandCount) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div v-if="hasSamples" class="performance-rail">
|
||||
<div ref="chartElement" class="rail-chart" aria-label="请求速率与接口 P95 趋势图" />
|
||||
<div ref="chartElement" class="rail-chart" :aria-label="t('performance.chartAria')" />
|
||||
</div>
|
||||
<div v-else class="samples-empty">
|
||||
数据源已连接,但该时间范围内尚未收到请求指标。
|
||||
{{ t('performance.noSamples') }}
|
||||
</div>
|
||||
|
||||
<div class="rankings">
|
||||
@@ -362,9 +358,9 @@ onUnmounted(disposeChart)
|
||||
<div class="ranking-heading">
|
||||
<div>
|
||||
<span>HTTP ROUTES</span>
|
||||
<h4>接口耗时排行</h4>
|
||||
<h4>{{ t('performance.endpointRanking') }}</h4>
|
||||
</div>
|
||||
<small>P95 / 请求量 / 5xx</small>
|
||||
<small>{{ t('performance.endpointMetrics') }}</small>
|
||||
</div>
|
||||
<div v-if="report.endpoints.length" class="ranking-list">
|
||||
<div
|
||||
@@ -383,20 +379,20 @@ onUnmounted(disposeChart)
|
||||
</div>
|
||||
<dl>
|
||||
<dd>{{ formatNumber(item.p95Milliseconds, 1) }} ms</dd>
|
||||
<dt>{{ formatNumber(item.requestCount) }} 次 · {{ formatNumber(item.exceptionalCount) }} 错误</dt>
|
||||
<dt>{{ t('performance.endpointCounts', { count: formatNumber(item.requestCount), errors: formatNumber(item.exceptionalCount) }) }}</dt>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="ranking-empty">该范围内没有接口指标。</p>
|
||||
<p v-else class="ranking-empty">{{ t('performance.noEndpoints') }}</p>
|
||||
</article>
|
||||
|
||||
<article class="ranking-board database-board">
|
||||
<div class="ranking-heading">
|
||||
<div>
|
||||
<span>DATABASE QUERIES</span>
|
||||
<h4>数据库查询排行</h4>
|
||||
<h4>{{ t('performance.databaseRanking') }}</h4>
|
||||
</div>
|
||||
<small>P95 / 调用量 / 慢查询</small>
|
||||
<small>{{ t('performance.databaseMetrics') }}</small>
|
||||
</div>
|
||||
<div v-if="report.databaseQueries.length" class="ranking-list">
|
||||
<div
|
||||
@@ -415,23 +411,23 @@ onUnmounted(disposeChart)
|
||||
</div>
|
||||
<dl>
|
||||
<dd>{{ formatNumber(item.p95Milliseconds, 1) }} ms</dd>
|
||||
<dt>{{ formatNumber(item.requestCount) }} 次 · {{ formatNumber(item.exceptionalCount) }} 慢</dt>
|
||||
<dt>{{ t('performance.databaseCounts', { count: formatNumber(item.requestCount), slow: formatNumber(item.exceptionalCount) }) }}</dt>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="ranking-empty">该范围内没有数据库指标。</p>
|
||||
<p v-else class="ranking-empty">{{ t('performance.noDatabase') }}</p>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<footer class="performance-foot">
|
||||
<span>生成于 {{ formatTime(report.generatedAt) }} · 页面数据采用短时缓存</span>
|
||||
<span>{{ t('performance.generatedAt', { date: formatTime(report.generatedAt) }) }}</span>
|
||||
<a
|
||||
v-if="report.dashboardUrl"
|
||||
:href="report.dashboardUrl"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
查看原始调用链
|
||||
{{ t('performance.viewTraces') }}
|
||||
<el-icon><TopRight /></el-icon>
|
||||
</a>
|
||||
</footer>
|
||||
|
||||
Reference in new issue
Block a user