Fix jwt-token
This commit is contained in:
@@ -132,35 +132,125 @@ router.get('/system-info', async (req, res) => {
|
||||
let containerMetrics = {};
|
||||
|
||||
const containerEndpoints = [
|
||||
// Application containers with custom health endpoints
|
||||
{ name: 'drone-detection-backend', url: 'http://drone-detection-backend:3000/health/metrics', type: 'app' },
|
||||
{ name: 'drone-detection-frontend', url: 'http://drone-detection-frontend:80/health/metrics', type: 'app' },
|
||||
{ name: 'drone-detection-management', url: 'http://drone-detection-management:3001/health/metrics', type: 'app' },
|
||||
// Application containers - use proper service names and ports
|
||||
{ name: 'frontend', url: 'http://frontend/health', type: 'app' },
|
||||
{ name: 'backend', url: 'http://backend:3000/health', type: 'app' },
|
||||
{ name: 'management', url: 'http://management:3001/health', type: 'app' },
|
||||
|
||||
// Database containers - try standard health endpoints
|
||||
{ name: 'postgres', url: 'http://postgres:5432', type: 'database' },
|
||||
{ name: 'redis', url: 'http://redis:6379', type: 'cache' },
|
||||
|
||||
// Infrastructure containers
|
||||
{ name: 'nginx', url: 'http://nginx:80/nginx_status', type: 'proxy' },
|
||||
{ name: 'nginx-proxy-manager', url: 'http://nginx-proxy-manager:81/api/health', type: 'proxy' }
|
||||
// Database containers - use proper connection checks
|
||||
{ name: 'postgres', url: 'postgres://postgres:5432', type: 'database' },
|
||||
{ name: 'redis', url: 'redis://redis:6379', type: 'cache' }
|
||||
];
|
||||
|
||||
// Try internal container health endpoints first
|
||||
try {
|
||||
const https = require('https');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
|
||||
const healthChecks = await Promise.allSettled(
|
||||
containerEndpoints.map(async ({ name, url, type }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// Handle database/redis connections differently
|
||||
if (type === 'database' && url.startsWith('postgres://')) {
|
||||
// Simple TCP connection test for postgres
|
||||
const socket = net.createConnection(5432, 'postgres');
|
||||
socket.setTimeout(3000);
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.destroy();
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'connected',
|
||||
type,
|
||||
source: 'tcp_check',
|
||||
port: 5432
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('error', (error) => {
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'unreachable',
|
||||
type,
|
||||
error: error.message,
|
||||
source: 'tcp_check_failed'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('timeout', () => {
|
||||
socket.destroy();
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'timeout',
|
||||
type,
|
||||
source: 'tcp_check_failed'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === 'cache' && url.startsWith('redis://')) {
|
||||
// Simple TCP connection test for redis
|
||||
const socket = net.createConnection(6379, 'redis');
|
||||
socket.setTimeout(3000);
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.destroy();
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'connected',
|
||||
type,
|
||||
source: 'tcp_check',
|
||||
port: 6379
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('error', (error) => {
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'unreachable',
|
||||
type,
|
||||
error: error.message,
|
||||
source: 'tcp_check_failed'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('timeout', () => {
|
||||
socket.destroy();
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'timeout',
|
||||
type,
|
||||
source: 'tcp_check_failed'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// HTTP health checks for app containers
|
||||
const urlObj = new URL(url);
|
||||
const client = urlObj.protocol === 'https:' ? https : http;
|
||||
|
||||
const req = client.request({
|
||||
hostname: urlObj.hostname,
|
||||
port: urlObj.port,
|
||||
path: urlObj.pathname,
|
||||
port: urlObj.port || (urlObj.protocol === 'https:' ? 443 : 80),
|
||||
path: urlObj.pathname || '/',
|
||||
method: 'GET',
|
||||
timeout: 3000
|
||||
}, (res) => {
|
||||
@@ -171,20 +261,52 @@ router.get('/system-info', async (req, res) => {
|
||||
const metrics = res.headers['content-type']?.includes('application/json')
|
||||
? JSON.parse(data)
|
||||
: { status: 'healthy', raw: data };
|
||||
resolve({ name, metrics: { ...metrics, type, source: 'health_endpoint' } });
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
...metrics,
|
||||
type,
|
||||
source: 'health_endpoint',
|
||||
httpStatus: res.statusCode
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
resolve({ name, metrics: { status: 'responding', type, source: 'basic_check', data: data.substring(0, 100) } });
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'responding',
|
||||
type,
|
||||
source: 'basic_check',
|
||||
httpStatus: res.statusCode,
|
||||
data: data.substring(0, 100)
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
resolve({ name, metrics: { status: 'unreachable', type, error: error.message, source: 'health_check_failed' } });
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'unreachable',
|
||||
type,
|
||||
error: error.message,
|
||||
source: 'health_check_failed'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('timeout', () => {
|
||||
req.destroy();
|
||||
resolve({ name, metrics: { status: 'timeout', type, source: 'health_check_failed' } });
|
||||
resolve({
|
||||
name,
|
||||
metrics: {
|
||||
status: 'timeout',
|
||||
type,
|
||||
source: 'health_check_failed'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.end();
|
||||
@@ -199,7 +321,7 @@ router.get('/system-info', async (req, res) => {
|
||||
});
|
||||
|
||||
} catch (healthError) {
|
||||
console.log('Container health checks failed, trying Docker stats...');
|
||||
console.log('Container health checks failed, trying Docker stats...', healthError.message);
|
||||
}
|
||||
|
||||
// Fallback to Docker stats for ALL containers (not just our apps)
|
||||
@@ -211,28 +333,42 @@ router.get('/system-info', async (req, res) => {
|
||||
lines.forEach(line => {
|
||||
const [container, cpu, memUsage, memPerc, netIO, blockIO] = line.split('\t');
|
||||
if (container && cpu) {
|
||||
// Determine container type
|
||||
// Map actual container names to our simplified names
|
||||
let simpleName = container;
|
||||
let type = 'unknown';
|
||||
const name = container.toLowerCase();
|
||||
if (name.includes('postgres') || name.includes('mysql') || name.includes('mongo')) type = 'database';
|
||||
else if (name.includes('redis') || name.includes('memcached')) type = 'cache';
|
||||
else if (name.includes('nginx') || name.includes('proxy') || name.includes('traefik')) type = 'proxy';
|
||||
else if (name.includes('drone-detection') || name.includes('uamils')) type = 'application';
|
||||
else if (name.includes('elasticsearch') || name.includes('kibana') || name.includes('logstash')) type = 'logging';
|
||||
else if (name.includes('prometheus') || name.includes('grafana')) type = 'monitoring';
|
||||
|
||||
containerMetrics[container] = {
|
||||
if (container.includes('frontend') || container.includes('nginx')) {
|
||||
simpleName = 'frontend';
|
||||
type = 'app';
|
||||
} else if (container.includes('backend') || container.includes('api')) {
|
||||
simpleName = 'backend';
|
||||
type = 'app';
|
||||
} else if (container.includes('management') || container.includes('admin')) {
|
||||
simpleName = 'management';
|
||||
type = 'app';
|
||||
} else if (container.includes('postgres') || container.includes('postgresql')) {
|
||||
simpleName = 'postgres';
|
||||
type = 'database';
|
||||
} else if (container.includes('redis')) {
|
||||
simpleName = 'redis';
|
||||
type = 'cache';
|
||||
}
|
||||
|
||||
// Use simplified name for consistency
|
||||
containerMetrics[simpleName] = {
|
||||
cpu: cpu,
|
||||
memory: { usage: memUsage, percentage: memPerc },
|
||||
network: netIO,
|
||||
disk: blockIO,
|
||||
type: type,
|
||||
source: 'docker_stats'
|
||||
source: 'docker_stats',
|
||||
status: 'running',
|
||||
container_name: container
|
||||
};
|
||||
}
|
||||
});
|
||||
} catch (dockerError) {
|
||||
console.log('Docker stats failed, trying compose and processes...');
|
||||
console.log('Docker stats failed, using TCP checks as final verification...', dockerError.message);
|
||||
|
||||
// Try container inspection via docker compose
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user