- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import { Controller, Get, Res, UseGuards } from "@nestjs/common";
|
|
import { ApiExcludeController } from "@nestjs/swagger";
|
|
import { PrismaService } from "../prisma/prisma.service";
|
|
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
|
|
import { RolesGuard } from "./guards/roles.guard";
|
|
import { Roles } from "./decorators/roles.decorator";
|
|
import type { Response } from "express";
|
|
|
|
@ApiExcludeController()
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles("Admin", "SUPER_ADMIN")
|
|
@Controller("metrics")
|
|
export class MetricsController {
|
|
private static requestCount = 0;
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
public static incrementRequestCount() {
|
|
this.requestCount++;
|
|
}
|
|
|
|
@Get()
|
|
async getMetrics(@Res() res: Response) {
|
|
const memory = process.memoryUsage();
|
|
const cpu = process.cpuUsage();
|
|
|
|
let dbStatus = 1;
|
|
try {
|
|
await this.prisma.$queryRaw`SELECT 1`;
|
|
} catch {
|
|
dbStatus = 0;
|
|
}
|
|
|
|
const uptime = process.uptime();
|
|
|
|
const responseText = `# HELP node_memory_rss_bytes Resident set size in bytes.
|
|
# TYPE node_memory_rss_bytes gauge
|
|
node_memory_rss_bytes ${memory.rss}
|
|
|
|
# HELP node_memory_heap_used_bytes Heap used in bytes.
|
|
# TYPE node_memory_heap_used_bytes gauge
|
|
node_memory_heap_used_bytes ${memory.heapUsed}
|
|
|
|
# HELP node_memory_heap_total_bytes Heap total in bytes.
|
|
# TYPE node_memory_heap_total_bytes gauge
|
|
node_memory_heap_total_bytes ${memory.heapTotal}
|
|
|
|
# HELP node_cpu_user_time_microseconds CPU user time in microseconds.
|
|
# TYPE node_cpu_user_time_microseconds counter
|
|
node_cpu_user_time_microseconds ${cpu.user}
|
|
|
|
# HELP node_cpu_system_time_microseconds CPU system time in microseconds.
|
|
# TYPE node_cpu_system_time_microseconds counter
|
|
node_cpu_system_time_microseconds ${cpu.system}
|
|
|
|
# HELP node_app_uptime_seconds Application uptime in seconds.
|
|
# TYPE node_app_uptime_seconds gauge
|
|
node_app_uptime_seconds ${uptime}
|
|
|
|
# HELP canino_db_connected Database connection status (1 = connected, 0 = disconnected).
|
|
# TYPE canino_db_connected gauge
|
|
canino_db_connected ${dbStatus}
|
|
|
|
# HELP canino_http_requests_total Total HTTP requests processed.
|
|
# TYPE canino_http_requests_total counter
|
|
canino_http_requests_total ${MetricsController.requestCount}
|
|
`;
|
|
|
|
res.set("Content-Type", "text/plain; version=0.0.4; charset=utf-8");
|
|
res.end(responseText);
|
|
}
|
|
}
|