feat(metrics): 指标改由 SQLite 提供(重启不清零)+ 月度用量导出
- 新增 _usage_snapshot():调用数/供应商/token/耗时(p50,p95) 走 api_calls 聚合, 运行时长/在途/熔断仍取内存;库不可用自动回落内存态 - 影响 /metrics、/metrics/prometheus、/health.models;口径从「启动以来」变「最近 90 天」 - token 落库:表加 4 列(老库自动 ALTER),用 rid contextvar + token 侧信道关联 - 新增 /logs/usage/monthly 与 /logs/usage/monthly/export(仅管理员)+ 前端月度用量弹窗 - 模型统计排除无模型行(匿名早失败不再显示 ?) - 版本 2.8.0 → 2.9.0
This commit is contained in:
1 parent
e1e7fc2566
commit
3af915910c
6 files changed
+320
-7
No files matched your search
@@ -229,6 +229,14 @@ export default {
|
||||
prompt: 'Prompt (request body, truncated)',
|
||||
completion: 'Completion (truncated)',
|
||||
loading: 'Loading…',
|
||||
usageTitle: 'Monthly usage',
|
||||
usageMonth: 'Month',
|
||||
usageTotal: '{n} calls this month',
|
||||
colCalls: 'Calls',
|
||||
colOk: 'OK',
|
||||
colFail: 'Failed',
|
||||
colFailRate: 'Fail rate',
|
||||
colModels: 'Models',
|
||||
},
|
||||
|
||||
users: {
|
||||
|
||||
@@ -229,6 +229,14 @@ export default {
|
||||
prompt: '提示词(请求体,截断记录)',
|
||||
completion: '回复(截断记录)',
|
||||
loading: '加载中…',
|
||||
usageTitle: '月度用量',
|
||||
usageMonth: '选择月份',
|
||||
usageTotal: '本月共 {n} 次调用',
|
||||
colCalls: '调用数',
|
||||
colOk: '成功',
|
||||
colFail: '失败',
|
||||
colFailRate: '失败率',
|
||||
colModels: '模型数',
|
||||
},
|
||||
|
||||
users: {
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
</el-select>
|
||||
<el-input v-model="kw" size="small" class="w200" clearable
|
||||
:placeholder="t('calllogs.keyword')" @keyup.enter="reload" />
|
||||
<el-date-picker v-model="month" type="month" size="small" class="w140"
|
||||
value-format="YYYY-MM" :placeholder="t('calllogs.usageMonth')" :clearable="false" />
|
||||
<el-button size="small" @click="openUsage">
|
||||
<Icon name="dash" :size="13" /><span>{{ t('calllogs.usageTitle') }}</span>
|
||||
</el-button>
|
||||
<span class="spacer" />
|
||||
<el-button size="small" :loading="loading" @click="reload">
|
||||
<Icon name="refresh" :size="13" /><span>{{ t('common.refresh') }}</span>
|
||||
@@ -70,6 +75,31 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 月度用量弹窗:按账号聚合 -->
|
||||
<el-dialog v-model="usageDlg" :title="t('calllogs.usageTitle')" width="760px" top="8vh">
|
||||
<div class="card-h" style="margin-bottom: 8px">
|
||||
<b>{{ usage.month || month }}</b>
|
||||
<span class="sub">{{ t('calllogs.usageTotal', { n: usage.total_calls || 0 }) }}</span>
|
||||
<span class="spacer" />
|
||||
<el-button size="small" @click="exportUsage">
|
||||
<Icon name="dl" :size="13" /><span>{{ t('common.export') }}</span>
|
||||
</el-button>
|
||||
</div>
|
||||
<el-table :data="usage.items || []" size="small" max-height="420">
|
||||
<el-table-column prop="account" :label="t('calllogs.colAccount')" min-width="120" />
|
||||
<el-table-column prop="calls" :label="t('calllogs.colCalls')" width="90" />
|
||||
<el-table-column prop="ok" :label="t('calllogs.colOk')" width="80" />
|
||||
<el-table-column prop="fail" :label="t('calllogs.colFail')" width="80" />
|
||||
<el-table-column :label="t('calllogs.colFailRate')" width="100">
|
||||
<template #default="{ row }">{{ row.calls ? (row.fail / row.calls * 100).toFixed(1) + '%' : '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('calllogs.colLatency')" width="100">
|
||||
<template #default="{ row }">{{ row.avg_ms }}ms</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="models" :label="t('calllogs.colModels')" width="90" />
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 详情弹窗:完整提示词 + 回复 -->
|
||||
<el-dialog v-model="dlg" :title="t('calllogs.detailTitle')" width="860px" top="6vh">
|
||||
<div v-if="detail" class="det">
|
||||
@@ -125,6 +155,37 @@ const kw = ref('')
|
||||
const dlg = ref(false)
|
||||
const detail = ref<any>(null)
|
||||
|
||||
// 月度用量(按账号聚合)
|
||||
const month = ref(new Date().toISOString().slice(0, 7))
|
||||
const usageDlg = ref(false)
|
||||
const usage = ref<any>({})
|
||||
|
||||
async function openUsage() {
|
||||
usageDlg.value = true
|
||||
try {
|
||||
usage.value = await api(`/logs/usage/monthly?month=${month.value}`)
|
||||
} catch {
|
||||
usage.value = { items: [] }
|
||||
}
|
||||
}
|
||||
|
||||
async function exportUsage() {
|
||||
const resp = await fetch(`/logs/usage/monthly/export?month=${month.value}`, {
|
||||
headers: { Authorization: `Bearer ${getToken()}` },
|
||||
})
|
||||
if (!resp.ok) return
|
||||
const blob = await resp.blob()
|
||||
const href = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = href
|
||||
a.download = `usage-${month.value}.csv`
|
||||
a.style.display = 'none'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
setTimeout(() => URL.revokeObjectURL(href), 10_000)
|
||||
}
|
||||
|
||||
const failCount = computed(() => rows.value.filter((r) => !r.ok).length)
|
||||
const avgMs = computed(() => {
|
||||
const v = rows.value.map((r) => Number(r.latency_ms)).filter((n) => Number.isFinite(n) && n > 0)
|
||||
|
||||
Reference in new issue
Block a user