This commit is contained in:
2025-10-10 10:28:36 +08:00
parent 204dd4781b
commit 71d5aabb84
10 changed files with 323 additions and 1185 deletions

View File

@@ -1,6 +1,5 @@
import { reactive } from 'vue'
import type { ResourceService } from './ResourceService'
import type { EventCommunicationService } from './EventCommunicationService'
import { v4 as uuidv4 } from 'uuid'
/**
@@ -107,11 +106,9 @@ export class ApplicationSandboxEngine {
private performanceData = reactive(new Map<string, SandboxPerformance[]>())
private monitoringInterval: number | null = null
private resourceService: ResourceService
private eventService: EventCommunicationService
constructor(resourceService: ResourceService, eventService: EventCommunicationService) {
constructor(resourceService: ResourceService) {
this.resourceService = resourceService
this.eventService = eventService
this.startPerformanceMonitoring()
}
@@ -1163,27 +1160,7 @@ export class ApplicationSandboxEngine {
/**
* 检查性能阈值
*/
private checkPerformanceThresholds(sandbox: SandboxInstance, metrics: SandboxPerformance): void {
// 内存使用检查
if (metrics.memoryUsage > sandbox.config.maxMemoryUsage) {
this.eventService.sendMessage('system', 'performance-alert', {
sandboxId: sandbox.id,
type: 'memory',
usage: metrics.memoryUsage,
limit: sandbox.config.maxMemoryUsage
})
}
// CPU使用检查
if (metrics.cpuUsage > sandbox.config.maxCpuUsage) {
this.eventService.sendMessage('system', 'performance-alert', {
sandboxId: sandbox.id,
type: 'cpu',
usage: metrics.cpuUsage,
limit: sandbox.config.maxCpuUsage
})
}
}
private checkPerformanceThresholds(sandbox: SandboxInstance, metrics: SandboxPerformance): void {}
/**
* 开始性能监控
@@ -1220,11 +1197,11 @@ export class ApplicationSandboxEngine {
const oldState = sandbox.state
sandbox.state = newState
// 触发状态变化事件
this.eventService.sendMessage('system', 'sandbox-state-change', {
sandboxId: sandbox.id,
newState,
oldState
})
// 移除事件服务消息发送
// this.eventService.sendMessage('system', 'sandbox-state-change', {
// sandboxId: sandbox.id,
// newState,
// oldState
// })
}
}