Fix jwt-token

This commit is contained in:
2025-09-14 18:14:42 +02:00
parent 264aafbf43
commit 047bae2acf
4 changed files with 507 additions and 26 deletions

View File

@@ -128,33 +128,83 @@ router.get('/system-info', async (req, res) => {
const tenantCount = await Tenant.count();
const userCount = await User.count();
// Get container metrics using Docker stats
// Get container metrics using internal health endpoints
let containerMetrics = {};
const containerEndpoints = [
{ name: 'drone-detection-backend', url: 'http://drone-detection-backend:3000/health/metrics' },
{ name: 'drone-detection-frontend', url: 'http://drone-detection-frontend:80/health/metrics' },
{ name: 'drone-detection-management', url: 'http://drone-detection-management:3001/health/metrics' }
];
// Try internal container health endpoints first
try {
const { stdout } = await execAsync('docker stats --no-stream --format "table {{.Container}}\\t{{.CPUPerc}}\\t{{.MemUsage}}\\t{{.MemPerc}}\\t{{.NetIO}}\\t{{.BlockIO}}"');
const lines = stdout.trim().split('\n').slice(1); // Remove header
const fetch = require('node-fetch');
const healthChecks = await Promise.allSettled(
containerEndpoints.map(async ({ name, url }) => {
const response = await fetch(url, { timeout: 3000 });
const metrics = await response.json();
return { name, metrics };
})
);
containerMetrics = lines.reduce((acc, line) => {
const [container, cpu, memUsage, memPerc, netIO, blockIO] = line.split('\t');
if (container.includes('drone-detection') || container.includes('uamils')) {
acc[container] = {
cpu: cpu,
memory: {
usage: memUsage,
percentage: memPerc
},
network: netIO,
disk: blockIO
healthChecks.forEach((result, index) => {
const containerName = containerEndpoints[index].name;
if (result.status === 'fulfilled') {
containerMetrics[containerName] = result.value.metrics;
} else {
containerMetrics[containerName] = {
status: 'health_check_failed',
error: result.reason?.message || 'Health endpoint unavailable'
};
}
return acc;
}, {});
} catch (dockerError) {
console.log('Docker stats not available:', dockerError.message);
containerMetrics = {
error: 'Docker not available or containers not running',
message: dockerError.message
};
});
} catch (healthError) {
console.log('Container health checks failed, trying Docker stats...');
// Fallback to Docker stats if health endpoints fail
try {
const { stdout } = await execAsync('docker stats --no-stream --format "table {{.Container}}\\t{{.CPUPerc}}\\t{{.MemUsage}}\\t{{.MemPerc}}\\t{{.NetIO}}\\t{{.BlockIO}}"');
const lines = stdout.trim().split('\n').slice(1);
containerMetrics = lines.reduce((acc, line) => {
const [container, cpu, memUsage, memPerc, netIO, blockIO] = line.split('\t');
if (container.includes('drone-detection') || container.includes('uamils')) {
acc[container] = {
cpu: cpu,
memory: { usage: memUsage, percentage: memPerc },
network: netIO,
disk: blockIO,
source: 'docker_stats'
};
}
return acc;
}, {});
} catch (dockerError) {
// Try container inspection via docker compose
try {
const { stdout: composeStatus } = await execAsync('docker-compose ps --format json');
const containers = JSON.parse(`[${composeStatus.split('\n').filter(line => line.trim()).join(',')}]`);
containerMetrics = containers.reduce((acc, container) => {
if (container.Name && (container.Name.includes('drone-detection') || container.Name.includes('uamils'))) {
acc[container.Name] = {
status: container.State,
health: container.Health || 'unknown',
ports: container.Ports,
source: 'docker_compose'
};
}
return acc;
}, {});
} catch (composeError) {
containerMetrics = {
error: 'All container monitoring methods failed',
attempts: ['health_endpoints', 'docker_stats', 'docker_compose'],
lastError: composeError.message
};
}
}
}
// Get system memory and CPU info