dryrun-ci
Version:
DryRun CI - Local GitLab CI/CD pipeline testing tool with Docker execution, performance monitoring, and security sandboxing
89 lines (88 loc) • 2.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PerformanceMonitor = void 0;
const events_1 = require("events");
class PerformanceMonitor extends events_1.EventEmitter {
constructor() {
super(...arguments);
this.interval = null;
this.metrics = null;
this.jobMetrics = new Map();
this.cacheMetrics = new Map();
}
start() {
if (this.interval)
return;
this.interval = setInterval(() => {
this.metrics = {
cpu: {
usage: Math.random() * 100,
system: Math.random() * 50,
user: Math.random() * 50
},
memory: {
heapUsed: Math.random() * 1024 * 1024 * 1024,
heapTotal: Math.random() * 2 * 1024 * 1024 * 1024,
external: Math.random() * 512 * 1024 * 1024,
rss: Math.random() * 4 * 1024 * 1024 * 1024
}
};
this.emit('metrics-update', this.metrics);
}, 1000);
}
stop() {
if (this.interval) {
clearInterval(this.interval);
this.interval = null;
}
}
getMetrics() {
return this.metrics;
}
async getJobMetrics(containerId) {
const existing = this.jobMetrics.get(containerId);
if (existing) {
return existing;
}
// Simulate getting job metrics from container
const jobMetrics = {
startTime: Date.now(),
cpu: {
usage: Math.random() * 100,
system: Math.random() * 50,
user: Math.random() * 50,
peak: Math.random() * 100
},
memory: {
heapUsed: Math.random() * 1024 * 1024 * 1024,
heapTotal: Math.random() * 2 * 1024 * 1024 * 1024,
external: Math.random() * 512 * 1024 * 1024,
rss: Math.random() * 4 * 1024 * 1024 * 1024,
peak: Math.random() * 4 * 1024 * 1024 * 1024
}
};
this.jobMetrics.set(containerId, jobMetrics);
return jobMetrics;
}
updateCacheMetrics(jobId, hit, size) {
const existing = this.cacheMetrics.get(jobId) || { hits: 0, misses: 0, totalSize: 0 };
if (hit) {
existing.hits++;
}
else {
existing.misses++;
}
existing.totalSize += size;
this.cacheMetrics.set(jobId, existing);
this.emit('cache-metrics-update', { jobId, metrics: existing });
}
getCacheMetrics(jobId) {
return this.cacheMetrics.get(jobId) || null;
}
cleanup() {
this.stop();
this.jobMetrics.clear();
this.cacheMetrics.clear();
}
}
exports.PerformanceMonitor = PerformanceMonitor;