check-24h-stats.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * 快速检查 24h LLM/TTS 统计
  3. */
  4. const { prisma } = require('../src/models');
  5. async function main() {
  6. const last24h = new Date(Date.now() - 24 * 60 * 60 * 1000);
  7. // LLM calls
  8. const llmCalls = await prisma.aiCallLog.groupBy({
  9. by: ['callType', 'provider'],
  10. where: { callType: { startsWith: 'llm' }, createdAt: { gte: last24h } },
  11. _count: { id: true },
  12. });
  13. llmCalls.sort((a: any, b: any) => b._count.id - a._count.id);
  14. console.log('=== 24h LLM 请求 ===');
  15. let total = 0;
  16. for (const c of llmCalls) {
  17. console.log(` ${c.callType.padEnd(25)} | ${(c.provider||'-').padEnd(20)} | ${c._count.id} 次`);
  18. total += c._count.id;
  19. }
  20. console.log(` LLM 总计: ${total} 次`);
  21. // TTS calls
  22. const ttsCalls = await prisma.aiCallLog.groupBy({
  23. by: ['callType', 'provider'],
  24. where: { callType: { startsWith: 'tts' }, createdAt: { gte: last24h } },
  25. _count: { id: true },
  26. });
  27. ttsCalls.sort((a: any, b: any) => b._count.id - a._count.id);
  28. console.log('\n=== 24h TTS 请求 ===');
  29. let ttsTotal = 0;
  30. for (const c of ttsCalls) {
  31. console.log(` ${c.callType.padEnd(25)} | ${(c.provider||'-').padEnd(20)} | ${c._count.id} 次`);
  32. ttsTotal += c._count.id;
  33. }
  34. console.log(` TTS 总计: ${ttsTotal} 次`);
  35. const all24h = await prisma.aiCallLog.count({ where: { createdAt: { gte: last24h } } });
  36. console.log(`\n 24h 全部请求: ${all24h} 次 (LLM ${total} + TTS ${ttsTotal})`);
  37. await prisma.$disconnect();
  38. }
  39. main().catch(e => { console.error(e); process.exit(1); });