Files
CapaKraken/apps/web/src/app/api/perf/route.ts
T
Hartmut cd78f72f33 chore: full technical rename planarchy → capakraken
Complete rename of all technical identifiers across the codebase:

Package names (11 packages):
- @planarchy/* → @capakraken/* in all package.json, tsconfig, imports

Import statements: 277 files, 548 occurrences replaced

Database & Docker:
- PostgreSQL user/db: planarchy → capakraken
- Docker volumes: planarchy_pgdata → capakraken_pgdata
- Connection strings updated in docker-compose, .env, CI

CI/CD:
- GitHub Actions workflow: all filter commands updated
- Test database credentials updated

Infrastructure:
- Redis channel: planarchy:sse → capakraken:sse
- Logger service name: planarchy-api → capakraken-api
- Anonymization seed updated
- Start/stop/restart scripts updated

Test data:
- Seed emails: @planarchy.dev → @capakraken.dev
- E2E test credentials: all 11 spec files updated
- Email defaults: @planarchy.app → @capakraken.app
- localStorage keys: planarchy_* → capakraken_*

Documentation: 30+ .md files updated

Verification:
- pnpm install: workspace resolution works
- TypeScript: only pre-existing TS2589 (no new errors)
- Engine: 310/310 tests pass
- Staffing: 37/37 tests pass

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-03-27 13:18:09 +01:00

68 lines
1.9 KiB
TypeScript

import { NextResponse } from "next/server";
import { eventBus } from "@capakraken/api/sse";
export const dynamic = "force-dynamic";
export const runtime = "nodejs";
/**
* GET /api/perf — Runtime performance metrics.
*
* Protected by CRON_SECRET header or query param.
* Returns Node.js memory usage, process uptime, and SSE connection count.
*/
export function GET(request: Request) {
const cronSecret = process.env["CRON_SECRET"];
if (cronSecret) {
const url = new URL(request.url);
const headerToken = request.headers.get("authorization")?.replace("Bearer ", "");
const queryToken = url.searchParams.get("token");
if (headerToken !== cronSecret && queryToken !== cronSecret) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
}
const mem = process.memoryUsage();
return NextResponse.json({
timestamp: new Date().toISOString(),
uptime: {
seconds: Math.round(process.uptime()),
formatted: formatUptime(process.uptime()),
},
memory: {
heapUsedMB: round(mem.heapUsed / 1024 / 1024),
heapTotalMB: round(mem.heapTotal / 1024 / 1024),
rssMB: round(mem.rss / 1024 / 1024),
externalMB: round(mem.external / 1024 / 1024),
arrayBuffersMB: round(mem.arrayBuffers / 1024 / 1024),
},
sse: {
activeConnections: eventBus.subscriberCount,
},
node: {
version: process.version,
platform: process.platform,
arch: process.arch,
},
});
}
function round(n: number): number {
return Math.round(n * 100) / 100;
}
function formatUptime(seconds: number): string {
const d = Math.floor(seconds / 86400);
const h = Math.floor((seconds % 86400) / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = Math.floor(seconds % 60);
const parts: string[] = [];
if (d > 0) parts.push(`${d}d`);
if (h > 0) parts.push(`${h}h`);
if (m > 0) parts.push(`${m}m`);
parts.push(`${s}s`);
return parts.join(" ");
}