klg-asutk-app/app/api/metrics/route.ts
Yuriy 0150aba4f5 Consolidation: KLG ASUTK + PAPA integration
- Unify API: lib/api.ts uses /api/v1, inbox uses /api/inbox (rewrites)
- Remove localhost refs: openapi, inbox page
- Add rewrites: /api/inbox|tmc -> inbox-server, /api/v1 -> FastAPI
- Add stub routes: knowledge/insights, recommendations, search, log-error
- Transfer from PAPA: prompts (inspection, tmc), scripts, supabase, data/tmc-requests
- Fix inbox-server: ORDER BY created_at, package.json
- Remove redundant app/api/inbox/files route (rewrites handle it)
- knowledge/ in gitignore (large PDFs)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 17:18:31 +03:00

82 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const dynamic = "force-dynamic";
import { NextRequest, NextResponse } from 'next/server';
import { metrics } from '@/lib/monitoring/metrics';
import { handleError } from '@/lib/error-handler';
import { rateLimit, getRateLimitIdentifier } from '@/lib/rate-limit';
/**
* API endpoint для получения метрик
*/
export async function GET(request: NextRequest) {
try {
// Rate limiting
const rateLimitResult = rateLimit(getRateLimitIdentifier(request), 100, 60000);
if (!rateLimitResult.allowed) {
return NextResponse.json(
{ error: 'Слишком много запросов' },
{ status: 429 }
);
}
const { searchParams } = new URL(request.url);
const type = searchParams.get('type') || 'all';
const endpoint = searchParams.get('endpoint');
const startTime = searchParams.get('startTime');
const endTime = searchParams.get('endTime');
const metricName = searchParams.get('metricName');
const periodMs = parseInt(searchParams.get('periodMs') || '60000');
if (type === 'performance') {
// Получить статистику по метрике производительности
const metricKey = endpoint ? `performance.${endpoint}` : 'performance';
const stats = metrics.getStats(metricKey, periodMs);
return NextResponse.json({
type: 'performance',
stats,
});
}
if (type === 'performance-details') {
// Получить детальные метрики производительности
const metricKey = endpoint ? `performance.${endpoint}` : 'performance';
const metricsData = metrics.getMetrics(
metricKey,
startTime ? new Date(startTime) : undefined,
endTime ? new Date(endTime) : undefined
);
return NextResponse.json({
type: 'performance-details',
metrics: metricsData,
count: metricsData.length,
});
}
if (metricName) {
// Получить статистику по конкретной метрике
const stats = metrics.getStats(metricName, periodMs);
return NextResponse.json({
metric: metricName,
stats,
});
}
// Все метрики
const allMetrics = metrics.getMetrics(
undefined,
startTime ? new Date(startTime) : undefined,
endTime ? new Date(endTime) : undefined
);
return NextResponse.json({
type: 'all',
metrics: allMetrics,
count: allMetrics.length,
});
} catch (error) {
return handleError(error, {
path: '/api/metrics',
method: 'GET',
});
}
}