align for IA agents + grafana
This commit is contained in:
parent
c49b8f86ec
commit
f5bfc4644c
@ -118,20 +118,20 @@ server {
|
|||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
# Configuration spécifique pour Grafana
|
# Configuration spécifique pour Grafana
|
||||||
proxy_set_header X-Grafana-Org-Id 1;
|
proxy_set_header X-Grafana-Org-Id 1;
|
||||||
|
|
||||||
# Support des WebSockets pour les live updates
|
# Support des WebSockets pour les live updates
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
# Timeouts
|
# Timeouts
|
||||||
proxy_connect_timeout 60s;
|
proxy_connect_timeout 60s;
|
||||||
proxy_send_timeout 60s;
|
proxy_send_timeout 60s;
|
||||||
proxy_read_timeout 60s;
|
proxy_read_timeout 60s;
|
||||||
|
|
||||||
# Buffer settings
|
# Buffer settings
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
proxy_request_buffering off;
|
proxy_request_buffering off;
|
||||||
@ -144,12 +144,12 @@ server {
|
|||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
# CORS pour les requêtes depuis Grafana
|
# CORS pour les requêtes depuis Grafana
|
||||||
add_header Access-Control-Allow-Origin *;
|
add_header Access-Control-Allow-Origin *;
|
||||||
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
||||||
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
|
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
|
||||||
|
|
||||||
if ($request_method = 'OPTIONS') {
|
if ($request_method = 'OPTIONS') {
|
||||||
return 204;
|
return 204;
|
||||||
}
|
}
|
||||||
@ -161,12 +161,12 @@ server {
|
|||||||
root /var/www/lecoffre/status;
|
root /var/www/lecoffre/status;
|
||||||
index index.html;
|
index index.html;
|
||||||
try_files $uri $uri/ =404;
|
try_files $uri $uri/ =404;
|
||||||
|
|
||||||
# Headers de sécurité
|
# Headers de sécurité
|
||||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
add_header X-Content-Type-Options "nosniff" always;
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
add_header X-XSS-Protection "1; mode=block" always;
|
add_header X-XSS-Protection "1; mode=block" always;
|
||||||
|
|
||||||
# Cache pour les assets statiques
|
# Cache pour les assets statiques
|
||||||
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ {
|
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg)$ {
|
||||||
expires 1h;
|
expires 1h;
|
||||||
@ -181,17 +181,17 @@ server {
|
|||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
# CORS pour les requêtes AJAX
|
# CORS pour les requêtes AJAX
|
||||||
add_header Access-Control-Allow-Origin *;
|
add_header Access-Control-Allow-Origin *;
|
||||||
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
||||||
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
|
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
|
||||||
|
|
||||||
# Timeouts
|
# Timeouts
|
||||||
proxy_connect_timeout 10s;
|
proxy_connect_timeout 10s;
|
||||||
proxy_send_timeout 10s;
|
proxy_send_timeout 10s;
|
||||||
proxy_read_timeout 10s;
|
proxy_read_timeout 10s;
|
||||||
|
|
||||||
if ($request_method = 'OPTIONS') {
|
if ($request_method = 'OPTIONS') {
|
||||||
return 204;
|
return 204;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ async function getContainerInfo(containerName) {
|
|||||||
|
|
||||||
async function getServiceHealth(containerName, port) {
|
async function getServiceHealth(containerName, port) {
|
||||||
if (!port) return 'unknown';
|
if (!port) return 'unknown';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { stdout } = await execAsync(`docker exec ${containerName} wget -q --spider -O- http://localhost:${port}/health 2>/dev/null || echo "unhealthy"`);
|
const { stdout } = await execAsync(`docker exec ${containerName} wget -q --spider -O- http://localhost:${port}/health 2>/dev/null || echo "unhealthy"`);
|
||||||
return stdout.trim() === 'unhealthy' ? 'unhealthy' : 'healthy';
|
return stdout.trim() === 'unhealthy' ? 'unhealthy' : 'healthy';
|
||||||
@ -80,12 +80,12 @@ async function checkExternalService(url) {
|
|||||||
response_time: 'N/A (WebSocket)'
|
response_time: 'N/A (WebSocket)'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
const client = urlObj.protocol === 'https:' ? https : http;
|
const client = urlObj.protocol === 'https:' ? https : http;
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const req = client.get(url, { timeout: 5000 }, (res) => {
|
const req = client.get(url, { timeout: 5000 }, (res) => {
|
||||||
resolve({
|
resolve({
|
||||||
@ -93,14 +93,14 @@ async function checkExternalService(url) {
|
|||||||
response_time: `${Date.now() - start}ms`
|
response_time: `${Date.now() - start}ms`
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', () => {
|
req.on('error', () => {
|
||||||
resolve({
|
resolve({
|
||||||
status: 'error',
|
status: 'error',
|
||||||
response_time: 'N/A'
|
response_time: 'N/A'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('timeout', () => {
|
req.on('timeout', () => {
|
||||||
resolve({
|
resolve({
|
||||||
status: 'timeout',
|
status: 'timeout',
|
||||||
@ -118,16 +118,16 @@ async function checkExternalService(url) {
|
|||||||
|
|
||||||
function calculateUptime(startedAt) {
|
function calculateUptime(startedAt) {
|
||||||
if (!startedAt || startedAt === 'N/A') return 'N/A';
|
if (!startedAt || startedAt === 'N/A') return 'N/A';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const start = new Date(startedAt);
|
const start = new Date(startedAt);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diff = now - start;
|
const diff = now - start;
|
||||||
|
|
||||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
||||||
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
||||||
|
|
||||||
if (days > 0) return `${days}j ${hours}h ${minutes}m`;
|
if (days > 0) return `${days}j ${hours}h ${minutes}m`;
|
||||||
if (hours > 0) return `${hours}h ${minutes}m`;
|
if (hours > 0) return `${hours}h ${minutes}m`;
|
||||||
return `${minutes}m`;
|
return `${minutes}m`;
|
||||||
@ -138,15 +138,15 @@ function calculateUptime(startedAt) {
|
|||||||
|
|
||||||
async function getServicesStatus() {
|
async function getServicesStatus() {
|
||||||
const servicesStatus = [];
|
const servicesStatus = [];
|
||||||
|
|
||||||
for (const service of services) {
|
for (const service of services) {
|
||||||
const containerInfo = await getContainerInfo(service.container);
|
const containerInfo = await getContainerInfo(service.container);
|
||||||
const [status, startedAt, image, ip, ports] = containerInfo.split('|');
|
const [status, startedAt, image, ip, ports] = containerInfo.split('|');
|
||||||
|
|
||||||
const portsArray = ports ? ports.split(' ').filter(p => p.trim()) : [];
|
const portsArray = ports ? ports.split(' ').filter(p => p.trim()) : [];
|
||||||
const health = await getServiceHealth(service.container, service.port);
|
const health = await getServiceHealth(service.container, service.port);
|
||||||
const uptime = calculateUptime(startedAt);
|
const uptime = calculateUptime(startedAt);
|
||||||
|
|
||||||
servicesStatus.push({
|
servicesStatus.push({
|
||||||
name: service.name,
|
name: service.name,
|
||||||
status: status === 'running' ? 'running' : 'stopped',
|
status: status === 'running' ? 'running' : 'stopped',
|
||||||
@ -159,13 +159,13 @@ async function getServicesStatus() {
|
|||||||
port: service.port
|
port: service.port
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return servicesStatus;
|
return servicesStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getExternalServicesStatus() {
|
async function getExternalServicesStatus() {
|
||||||
const externalStatus = [];
|
const externalStatus = [];
|
||||||
|
|
||||||
for (const service of externalServices) {
|
for (const service of externalServices) {
|
||||||
const status = await checkExternalService(service.url);
|
const status = await checkExternalService(service.url);
|
||||||
externalStatus.push({
|
externalStatus.push({
|
||||||
@ -175,7 +175,7 @@ async function getExternalServicesStatus() {
|
|||||||
...status
|
...status
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return externalStatus;
|
return externalStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ app.get('/api', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const services = await getServicesStatus();
|
const services = await getServicesStatus();
|
||||||
const external = await getExternalServicesStatus();
|
const external = await getExternalServicesStatus();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
services: services,
|
services: services,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user