20 lines
731 B
TypeScript
20 lines
731 B
TypeScript
import { Controller, Get, Header, Res } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiExcludeEndpoint } from '@nestjs/swagger';
|
|
import { Response } from 'express';
|
|
import { MetricsService } from './metrics.service';
|
|
|
|
@ApiTags('Metrics')
|
|
@Controller('metrics')
|
|
export class MetricsController {
|
|
constructor(private readonly metricsService: MetricsService) {}
|
|
|
|
@Get()
|
|
@ApiExcludeEndpoint() // 不在 Swagger 文档中显示
|
|
@ApiOperation({ summary: 'Prometheus 指标端点' })
|
|
async getMetrics(@Res() res: Response): Promise<void> {
|
|
const metrics = await this.metricsService.getMetrics();
|
|
res.header('Content-Type', this.metricsService.getContentType());
|
|
res.send(metrics);
|
|
}
|
|
}
|