fix(center): 数据看板与概览补齐「已取消」运行统计
- 壳子上报 start + 终态(done/error/cancelled),统计只认 start 作总数、done 作成功、error 作失败,cancelled 三类都不进,导致 成功+失败 ≠ 总数 - /api/admin/stats:新增 runs.cancelled / runs.triggered,total 改为终态记录数,failed 纳入 running(未收尾中断),trend 与 topPlugins 补 cancelled;成功+失败+取消严格等于总数 - 数据看板:hero 加取消徽标与口径说明,运行构成环图三段,趋势加取消线,插件排行显示取消数;概览运行卡片扩为 5 张(含已取消) - 成功率口径不变:success/(success+failed),取消不进分母
This commit is contained in:
@@ -105,16 +105,21 @@ export class AdminOpsController extends BaseController {
|
||||
(SELECT COUNT(*) FROM plugins WHERE status='revoked') AS revoked`))[0];
|
||||
const runs: any = (await m.query(
|
||||
`SELECT (SELECT COUNT(*) FROM runtime_reports WHERE status='start') AS started,
|
||||
(SELECT COUNT(*) FROM runtime_reports WHERE status <> 'start') AS finished,
|
||||
(SELECT COUNT(*) FROM runtime_reports WHERE status IN ('done','success')) AS success,
|
||||
(SELECT COUNT(*) FROM runtime_reports WHERE status IN ('error','failed')) AS failed,
|
||||
(SELECT COUNT(*) FROM runtime_reports
|
||||
WHERE status IN ('error','failed','running')) AS failed,
|
||||
(SELECT COUNT(*) FROM runtime_reports WHERE status IN ('cancel','cancelled','canceled')) AS cancelled,
|
||||
(SELECT COALESCE(SUM(duration_sec),0) FROM runtime_reports) AS duration_sec,
|
||||
(SELECT COUNT(DISTINCT account) FROM runtime_reports WHERE account <> '') AS active_users,
|
||||
(SELECT COUNT(DISTINCT plugin_id) FROM runtime_reports WHERE plugin_id <> '') AS active_plugins`))[0];
|
||||
// 取消(用户强制停止 / 排队取消 / 排队超时 / 客户端退出)也落终态,必须计入构成,否则 总数 ≠ 成功+失败
|
||||
const trendRows: any[] = await m.query(
|
||||
`SELECT LEFT(at,10) AS day,
|
||||
SUM(CASE WHEN status='start' THEN 1 ELSE 0 END) AS runs,
|
||||
SUM(CASE WHEN status IN ('done','success') THEN 1 ELSE 0 END) AS success,
|
||||
SUM(CASE WHEN status IN ('error','failed') THEN 1 ELSE 0 END) AS failed
|
||||
SUM(CASE WHEN status IN ('error','failed','running') THEN 1 ELSE 0 END) AS failed,
|
||||
SUM(CASE WHEN status IN ('cancel','cancelled','canceled') THEN 1 ELSE 0 END) AS cancelled
|
||||
FROM runtime_reports WHERE at >= CURDATE() - INTERVAL 13 DAY GROUP BY day ORDER BY day`);
|
||||
const trendMap: Record<string, any> = {};
|
||||
for (const r of trendRows) trendMap[r.day] = r;
|
||||
@@ -124,13 +129,20 @@ export class AdminOpsController extends BaseController {
|
||||
const day = new Date(d.getTime() - i * 86400000);
|
||||
const key = `${day.getFullYear()}-${String(day.getMonth() + 1).padStart(2, '0')}-${String(day.getDate()).padStart(2, '0')}`;
|
||||
const r = trendMap[key];
|
||||
trend.push({ day: key.slice(5), runs: Number(r?.runs || 0), success: Number(r?.success || 0), failed: Number(r?.failed || 0) });
|
||||
trend.push({
|
||||
day: key.slice(5),
|
||||
runs: Number(r?.runs || 0),
|
||||
success: Number(r?.success || 0),
|
||||
failed: Number(r?.failed || 0),
|
||||
cancelled: Number(r?.cancelled || 0),
|
||||
});
|
||||
}
|
||||
const topPlugins: any[] = await m.query(
|
||||
`SELECT plugin_id AS pluginId, COUNT(*) AS runs,
|
||||
SUM(CASE WHEN status='start' THEN 1 ELSE 0 END) AS triggered,
|
||||
SUM(CASE WHEN status IN ('done','success') THEN 1 ELSE 0 END) AS success,
|
||||
SUM(CASE WHEN status IN ('error','failed') THEN 1 ELSE 0 END) AS failed,
|
||||
SUM(CASE WHEN status IN ('cancel','cancelled','canceled') THEN 1 ELSE 0 END) AS cancelled,
|
||||
COALESCE(SUM(duration_sec),0) AS durationSec
|
||||
FROM runtime_reports GROUP BY plugin_id ORDER BY triggered DESC LIMIT 8`);
|
||||
const pnames: Record<string, string> = {};
|
||||
@@ -143,9 +155,26 @@ export class AdminOpsController extends BaseController {
|
||||
return {
|
||||
users: { total: Number(users.total || 0), admins: Number(users.admins || 0), authorized: Number(users.authorized || 0) },
|
||||
plugins: { total: Number(plugins.total || 0), published: Number(plugins.published || 0), testing: Number(plugins.testing || 0), disabled: Number(plugins.disabled || 0), revoked: Number(plugins.revoked || 0) },
|
||||
runs: { total: Number(runs.started || 0), success: Number(runs.success || 0), failed: Number(runs.failed || 0), durationSec: Number(runs.duration_sec || 0), activeUsers: Number(runs.active_users || 0), activePlugins: Number(runs.active_plugins || 0) },
|
||||
runs: {
|
||||
// total = 终态记录数(成功+失败+取消),保证三者相加严格等于总数;triggered = 开始上报数(含正在跑/排队取消没开始的)
|
||||
total: Number(runs.finished || 0),
|
||||
triggered: Number(runs.started || 0),
|
||||
success: Number(runs.success || 0),
|
||||
failed: Number(runs.failed || 0),
|
||||
cancelled: Number(runs.cancelled || 0),
|
||||
durationSec: Number(runs.duration_sec || 0),
|
||||
activeUsers: Number(runs.active_users || 0),
|
||||
activePlugins: Number(runs.active_plugins || 0),
|
||||
},
|
||||
trend,
|
||||
topPlugins: topPlugins.map((tp: any) => ({ ...tp, name: pnames[tp.pluginId] || tp.pluginId, runs: Number(tp.triggered || 0) })),
|
||||
topPlugins: topPlugins.map((tp: any) => ({
|
||||
...tp,
|
||||
name: pnames[tp.pluginId] || tp.pluginId,
|
||||
runs: Number(tp.triggered || 0),
|
||||
success: Number(tp.success || 0),
|
||||
failed: Number(tp.failed || 0),
|
||||
cancelled: Number(tp.cancelled || 0),
|
||||
})),
|
||||
topUsers: topUsers.map((tu: any) => ({ account: tu.account, runs: Number(tu.runs || 0), nickname: nick[tu.account] || '' })),
|
||||
today: d.toISOString().slice(0, 10),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user