Files
pos-system/services/_template/src/modules/metrics/metrics.controller.ts

36 lines
1.1 KiB
TypeScript

import { logger } from '@goodgo/logger';
import { Request, Response } from 'express';
import { register } from 'prom-client';
/**
* EN: Controller for handling metrics requests
* VI: Controller xử lý các request liên quan đến metrics
*/
export class MetricsController {
/**
* EN: Get current metrics in Prometheus format
* VI: Lấy metrics hiện tại theo định dạng Prometheus
*
* @param _req - Express request (unused/chưa dùng)
* @param res - Express response
*/
public async getMetrics(_req: Request, res: Response): Promise<void> {
try {
// EN: Set content type for Prometheus
// VI: Thiết lập content type cho Prometheus
res.set('Content-Type', register.contentType);
// EN: Return metrics
// VI: Trả về metrics
res.end(await register.metrics());
} catch (error) {
// EN: Log error and return 500
// VI: Ghi log lỗi và trả về 500
logger.error('Error getting metrics', { error });
res.status(500).send('Error getting metrics');
}
}
}