Files
telegram-management-system/backend-nestjs/src/modules/analytics/controllers/performance.controller.ts
你的用户名 237c7802e5
Some checks failed
Deploy / deploy (push) Has been cancelled
Initial commit: Telegram Management System
Full-stack web application for Telegram management
- Frontend: Vue 3 + Vben Admin
- Backend: NestJS
- Features: User management, group broadcast, statistics

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 15:37:50 +08:00

93 lines
2.9 KiB
TypeScript

import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { JwtAuthGuard } from '@common/guards/jwt-auth.guard';
import { RolesGuard } from '@common/guards/roles.guard';
import { Roles } from '@common/decorators/roles.decorator';
import { ApiOkResponse } from '@common/decorators/api-response.decorator';
import { CacheShort, CacheMedium } from '@common/decorators/cache.decorator';
import { PerformanceService } from '@common/services/performance.service';
@ApiTags('Performance - 性能监控')
@Controller('performance')
@UseGuards(JwtAuthGuard, RolesGuard)
export class PerformanceController {
constructor(private readonly performanceService: PerformanceService) {}
/**
* 获取性能概览
*/
@Get('overview')
@ApiOperation({ summary: '获取性能概览' })
@ApiOkResponse('性能概览获取成功')
@Roles('admin', 'operator')
@CacheShort('performance_overview')
async getPerformanceOverview() {
return await this.performanceService.getPerformanceOverview();
}
/**
* 获取当前系统指标
*/
@Get('metrics/current')
@ApiOperation({ summary: '获取当前系统指标' })
@ApiOkResponse('当前系统指标获取成功')
@Roles('admin', 'operator')
async getCurrentMetrics() {
return await this.performanceService.getCurrentSystemMetrics();
}
/**
* 获取内存使用分析
*/
@Get('memory')
@ApiOperation({ summary: '获取内存使用分析' })
@ApiOkResponse('内存使用分析获取成功')
@Roles('admin', 'operator')
@CacheShort('memory_analysis')
async getMemoryAnalysis() {
return await this.performanceService.analyzeMemoryUsage();
}
/**
* 获取慢查询列表
*/
@Get('slow-queries')
@ApiOperation({ summary: '获取慢查询列表' })
@ApiOkResponse('慢查询列表获取成功')
@Roles('admin', 'operator')
async getSlowQueries(
@Query('startDate') startDate: string,
@Query('endDate') endDate: string,
@Query('limit') limit: number = 10,
) {
const start = startDate ? new Date(startDate) : new Date(Date.now() - 24 * 60 * 60 * 1000);
const end = endDate ? new Date(endDate) : new Date();
return await this.performanceService.getSlowQueries(start, end, limit);
}
/**
* 获取最新性能报告
*/
@Get('report/latest')
@ApiOperation({ summary: '获取最新性能报告' })
@ApiOkResponse('最新性能报告获取成功')
@Roles('admin', 'operator')
async getLatestReport() {
return await this.performanceService.getLatestPerformanceReport();
}
/**
* 获取优化建议
*/
@Get('optimization/suggestions')
@ApiOperation({ summary: '获取性能优化建议' })
@ApiOkResponse('性能优化建议获取成功')
@Roles('admin', 'operator')
@CacheMedium('optimization_suggestions')
async getOptimizationSuggestions() {
return await this.performanceService.getOptimizationSuggestions();
}
}