容量管理: zones.rs 直读 nginx file_cache 共享内存记账(双轴: 磁盘 + keys_zone 索引内存), ?scan=1 扫盘上限 20 万文件; POST /api/admin/cache/purge 整区清理(只删文件不删目录, 根治 [crit] mkdir failed); POST /api/admin/cache/invalidate 按制品精准失效(预览->确认两步式, glob/子串, 删除上限 5000/扫描上限 20 万); GET /api/admin/cache 新增 capacity 块; 前端容量面板 + 按制品失效工具条; 测试 test-cache-capacity.sh 48/48(容量 27 + 精准失效 21, 含 EXPECT_MIN 护栏与前端静态契约); docs 容量管理章节
96 lines
3.5 KiB
JavaScript
96 lines
3.5 KiB
JavaScript
/* 数据总览:卡片 + 趋势图 + Top 排名条形图 */
|
||
(function () {
|
||
"use strict";
|
||
|
||
var C = { req: "#2563eb", in: "#0d9488", out: "#7c3aed" };
|
||
|
||
function num(v) { return Number(v) || 0; }
|
||
|
||
/// 可用模型 = 全部(启用中的)上游登记模型去重后的条数
|
||
function distinctModels(s) {
|
||
var seen = {};
|
||
s.upstreams.forEach(function (u) {
|
||
if (!u.enabled) return;
|
||
IP.arr(u.models).forEach(function (m) { seen[m] = true; });
|
||
});
|
||
return Object.keys(seen).length;
|
||
}
|
||
|
||
function renderCards(s) {
|
||
var active = s.domains.filter(function (d) { return d.status === "approved"; }).length;
|
||
var tot = s.usage.total || {};
|
||
var tok = s.usage.tokens || {};
|
||
|
||
IP.$("statPending").textContent = s.pending;
|
||
IP.$("statDomains").textContent = s.domains.length;
|
||
IP.$("statActive").textContent = active;
|
||
IP.$("statUsers").textContent = s.users.length;
|
||
IP.$("statUpstreams").textContent = s.upstreams.length;
|
||
IP.$("statLlmtoday").textContent = tot.today || 0;
|
||
IP.$("statLlmtotal").textContent = tot.total || 0;
|
||
|
||
var tokToday = num(tok.in_today) + num(tok.out_today);
|
||
var tokTotal = num(tok.in_total) + num(tok.out_total);
|
||
IP.$("statTokToday").textContent = IP.chart.fmtNum(tokToday);
|
||
IP.$("statTokTotal").textContent = IP.chart.fmtNum(tokTotal);
|
||
// 1.0.32:自服务上线以来累计(来自 audit meta.jsonl 真源,不受 stats 落盘/恢复影响)
|
||
var allTime = tok.all_time || {};
|
||
var allTimeTokens = num(allTime.tin) + num(allTime.tout);
|
||
IP.$("statTokAllTime").textContent = IP.chart.fmtNum(allTimeTokens) +
|
||
(allTime.since ? " (" + allTime.since + " 起)" : "");
|
||
IP.$("statModels").textContent = distinctModels(s);
|
||
}
|
||
|
||
function renderTrend(s) {
|
||
var t = s.trend;
|
||
if (!t || !t.labels || !t.labels.length) {
|
||
IP.chart.line(IP.$("chReq"), { labels: [], series: [] });
|
||
IP.chart.line(IP.$("chTok"), { labels: [], series: [] });
|
||
return;
|
||
}
|
||
IP.chart.line(IP.$("chReq"), {
|
||
labels: t.labels,
|
||
series: [{ name: "请求数", values: t.total.requests, color: C.req }]
|
||
});
|
||
IP.chart.line(IP.$("chTok"), {
|
||
labels: t.labels,
|
||
series: [
|
||
{ name: "入 token", values: t.total["in"], color: C["in"] },
|
||
{ name: "出 token", values: t.total.out, color: C.out }
|
||
]
|
||
});
|
||
}
|
||
|
||
/// 取累计调用 Top N,按累计降序;全 0 的不进榜(榜上堆一排 0 没信息量)
|
||
function top(list, key, n) {
|
||
return list
|
||
.filter(function (x) { return num(x[key]) > 0; })
|
||
.sort(function (a, b) { return num(b[key]) - num(a[key]); })
|
||
.slice(0, n);
|
||
}
|
||
|
||
function renderRanks(s) {
|
||
var byUser = top(s.usage.users || [], "total", 8).map(function (u) {
|
||
var owner = (s.users.filter(function (x) { return x.username === u.username; })[0] || {});
|
||
return {
|
||
label: IP.displayName(owner) + "(@" + u.username + ")",
|
||
value: num(u.total),
|
||
sub: "今 " + num(u.today)
|
||
};
|
||
});
|
||
IP.chart.bars(IP.$("chUsers"), { items: byUser, emptyText: "还没有任何 LLM 调用" });
|
||
|
||
var bySlot = top(s.usage.models || [], "total", 8).map(function (m) {
|
||
return { label: m.slot, value: num(m.total), sub: "今 " + num(m.today) };
|
||
});
|
||
IP.chart.bars(IP.$("chSlots"), { items: bySlot, emptyText: "还没有任何 LLM 调用" });
|
||
}
|
||
|
||
IP.boot("overview", function (s) {
|
||
renderCards(s);
|
||
renderTrend(s);
|
||
renderRanks(s);
|
||
if (IP.review) IP.review.render(s);
|
||
});
|
||
})();
|