First
Some checks failed
Build All Docker Images / changes (push) Has been cancelled
Build and Push App Docker Image / build (push) Has been cancelled
Build and Push Node Docker Image / build (push) Has been cancelled
Test and Lint / test-app (push) Has been cancelled
Test and Lint / test-node (push) Has been cancelled
Test and Lint / lint-dockerfiles (push) Has been cancelled
Test and Lint / security-scan (push) Has been cancelled
Build All Docker Images / build-app (push) Has been cancelled
Build All Docker Images / build-node (push) Has been cancelled
Build All Docker Images / summary (push) Has been cancelled
Some checks failed
Build All Docker Images / changes (push) Has been cancelled
Build and Push App Docker Image / build (push) Has been cancelled
Build and Push Node Docker Image / build (push) Has been cancelled
Test and Lint / test-app (push) Has been cancelled
Test and Lint / test-node (push) Has been cancelled
Test and Lint / lint-dockerfiles (push) Has been cancelled
Test and Lint / security-scan (push) Has been cancelled
Build All Docker Images / build-app (push) Has been cancelled
Build All Docker Images / build-node (push) Has been cancelled
Build All Docker Images / summary (push) Has been cancelled
This commit is contained in:
commit
4169337dd0
68 changed files with 8726 additions and 0 deletions
78
node/src/routes/status.ts
Normal file
78
node/src/routes/status.ts
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import { Router, Request, Response } from 'express';
|
||||
import { DockerManager } from '../services/dockerManager.js';
|
||||
import { logger } from '../utils/logger.js';
|
||||
|
||||
const router = Router();
|
||||
const dockerManager = new DockerManager();
|
||||
|
||||
// Get overall server status
|
||||
router.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const [gameServers, systemStats, runningContainers] = await Promise.all([
|
||||
dockerManager.listGameServers(),
|
||||
dockerManager.getSystemStats(),
|
||||
dockerManager.getRunningContainers()
|
||||
]);
|
||||
|
||||
const activePorts = new Set<number>();
|
||||
runningContainers.forEach((container: any) => {
|
||||
if (container.Ports) {
|
||||
container.Ports.forEach((port: any) => {
|
||||
if (port.PublicPort) {
|
||||
activePorts.add(port.PublicPort);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
res.json({
|
||||
timestamp: new Date().toISOString(),
|
||||
status: 'operational',
|
||||
gameServers: {
|
||||
available: gameServers.available,
|
||||
running: gameServers.running.length,
|
||||
runningServers: gameServers.running
|
||||
},
|
||||
activePorts: Array.from(activePorts).sort(),
|
||||
systemStats,
|
||||
containers: {
|
||||
total: runningContainers.length,
|
||||
running: runningContainers.filter((c: any) => c.State === 'running').length
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error getting server status:', error);
|
||||
res.status(500).json({ error: 'Failed to get server status' });
|
||||
}
|
||||
});
|
||||
|
||||
// Get active ports and services
|
||||
router.get('/ports', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const containers = await dockerManager.getRunningContainers();
|
||||
const portMappings: { [key: number]: string } = {};
|
||||
|
||||
containers.forEach((container: any) => {
|
||||
if (container.Ports && container.State === 'running') {
|
||||
container.Ports.forEach((port: any) => {
|
||||
if (port.PublicPort) {
|
||||
const serviceName = container.Labels?.['game-server'] ||
|
||||
container.Names[0]?.replace('/', '') ||
|
||||
'unknown';
|
||||
portMappings[port.PublicPort] = serviceName;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
res.json({
|
||||
activePorts: portMappings,
|
||||
totalPorts: Object.keys(portMappings).length
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error getting port information:', error);
|
||||
res.status(500).json({ error: 'Failed to get port information' });
|
||||
}
|
||||
});
|
||||
|
||||
export { router as statusRouter };
|
||||
Loading…
Add table
Add a link
Reference in a new issue