Sync DNS2 production changes - removed obsolete test suite and refactored structure

This commit is contained in:
Krystie
2026-03-23 10:47:15 +01:00
parent 1ac50918ab
commit d76644d948
288 changed files with 8965 additions and 15731 deletions

View File

@@ -144,28 +144,28 @@ class ResourceMonitor extends EventEmitter {
timestamp: new Date().toISOString(),
cpu: {
percent: Math.round(cpuPercent * 100) / 100,
usage: stats.cpu_stats.cpu_usage.total_usage,
usage: stats.cpu_stats.cpu_usage.total_usage
},
memory: {
usage: memoryUsage,
limit: memoryLimit,
percent: Math.round(memoryPercent * 100) / 100,
usageMB: Math.round(memoryUsage / 1024 / 1024),
limitMB: Math.round(memoryLimit / 1024 / 1024),
limitMB: Math.round(memoryLimit / 1024 / 1024)
},
network: {
rxBytes: networkRx,
txBytes: networkTx,
rxMB: Math.round(networkRx / 1024 / 1024 * 100) / 100,
txMB: Math.round(networkTx / 1024 / 1024 * 100) / 100,
txMB: Math.round(networkTx / 1024 / 1024 * 100) / 100
},
disk: {
readBytes: blockRead,
writeBytes: blockWrite,
readMB: Math.round(blockRead / 1024 / 1024 * 100) / 100,
writeMB: Math.round(blockWrite / 1024 / 1024 * 100) / 100,
writeMB: Math.round(blockWrite / 1024 / 1024 * 100) / 100
},
pids: stats.pids_stats?.current || 0,
pids: stats.pids_stats?.current || 0
});
});
});
@@ -178,7 +178,7 @@ class ResourceMonitor extends EventEmitter {
if (!this.stats.has(containerId)) {
this.stats.set(containerId, {
name: containerName,
history: [],
history: []
});
}
@@ -189,7 +189,7 @@ class ResourceMonitor extends EventEmitter {
// Keep only recent stats (based on retention policy)
const cutoffTime = Date.now() - (STATS_RETENTION_HOURS * 60 * 60 * 1000);
containerStats.history = containerStats.history.filter(s =>
new Date(s.timestamp).getTime() > cutoffTime,
new Date(s.timestamp).getTime() > cutoffTime
);
}
@@ -216,7 +216,7 @@ class ResourceMonitor extends EventEmitter {
severity: 'warning',
message: `CPU usage ${stats.cpu.percent.toFixed(1)}% exceeds threshold ${alertConfig.cpuThreshold}%`,
value: stats.cpu.percent,
threshold: alertConfig.cpuThreshold,
threshold: alertConfig.cpuThreshold
});
}
@@ -227,7 +227,7 @@ class ResourceMonitor extends EventEmitter {
severity: 'warning',
message: `Memory usage ${stats.memory.percent.toFixed(1)}% exceeds threshold ${alertConfig.memoryThreshold}%`,
value: stats.memory.percent,
threshold: alertConfig.memoryThreshold,
threshold: alertConfig.memoryThreshold
});
}
@@ -240,7 +240,7 @@ class ResourceMonitor extends EventEmitter {
severity: 'warning',
message: `Disk I/O ${diskIO.toFixed(1)} MB/s exceeds threshold ${alertConfig.diskIOThreshold} MB/s`,
value: diskIO,
threshold: alertConfig.diskIOThreshold,
threshold: alertConfig.diskIOThreshold
});
}
}
@@ -254,7 +254,7 @@ class ResourceMonitor extends EventEmitter {
timestamp: new Date().toISOString(),
alerts,
stats,
config: alertConfig,
config: alertConfig
});
// Auto-restart if configured
@@ -278,7 +278,7 @@ class ResourceMonitor extends EventEmitter {
containerId,
containerName,
timestamp: new Date().toISOString(),
reason: alerts,
reason: alerts
});
} catch (error) {
console.error(`[ResourceMonitor] Failed to restart ${containerName}:`, error.message);
@@ -306,7 +306,7 @@ class ResourceMonitor extends EventEmitter {
const cutoffTime = Date.now() - (hours * 60 * 60 * 1000);
return containerStats.history.filter(s =>
new Date(s.timestamp).getTime() > cutoffTime,
new Date(s.timestamp).getTime() > cutoffTime
);
}
@@ -325,16 +325,16 @@ class ResourceMonitor extends EventEmitter {
current: cpuValues[cpuValues.length - 1],
avg: cpuValues.reduce((a, b) => a + b, 0) / cpuValues.length,
max: Math.max(...cpuValues),
min: Math.min(...cpuValues),
min: Math.min(...cpuValues)
},
memory: {
current: memoryValues[memoryValues.length - 1],
avg: memoryValues.reduce((a, b) => a + b, 0) / memoryValues.length,
max: Math.max(...memoryValues),
min: Math.min(...memoryValues),
min: Math.min(...memoryValues)
},
dataPoints: history.length,
timeRange: hours,
timeRange: hours
};
}
@@ -352,7 +352,7 @@ class ResourceMonitor extends EventEmitter {
name: data.name,
current,
aggregated,
alertConfig: this.alerts.get(containerId),
alertConfig: this.alerts.get(containerId)
};
}
@@ -370,7 +370,7 @@ class ResourceMonitor extends EventEmitter {
diskIOThreshold: config.diskIOThreshold || null,
cooldownMinutes: config.cooldownMinutes || 15,
autoRestart: config.autoRestart || false,
notificationChannels: config.notificationChannels || [],
notificationChannels: config.notificationChannels || []
});
this.saveAlertConfig();
@@ -400,7 +400,7 @@ class ResourceMonitor extends EventEmitter {
for (const [containerId, data] of this.stats.entries()) {
data.history = data.history.filter(s =>
new Date(s.timestamp).getTime() > cutoffTime,
new Date(s.timestamp).getTime() > cutoffTime
);
// Remove container stats if no recent data
@@ -471,7 +471,7 @@ class ResourceMonitor extends EventEmitter {
return {
stats: Object.fromEntries(this.stats),
alerts: Object.fromEntries(this.alerts),
exportedAt: new Date().toISOString(),
exportedAt: new Date().toISOString()
};
}