document.addEventListener('DOMContentLoaded', function() {
// Sample data - replace with real API calls
const systems = [
{ name: 'Web Server', ip: '192.168.1.10', status: 'up', response: 120 },
{ name: 'Database', ip: '192.168.1.20', status: 'up', response: 45 },
{ name: 'API Gateway', ip: 'api.example.com', status: 'down', response: 0 },
{ name: 'Load Balancer', ip: 'lb.example.com', status: 'up', response: 30 },
{ name: 'Firewall', ip: '192.168.1.1', status: 'up', response: 5 }
];
const uptimeData = {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
datasets: [{
label: 'Uptime %',
data: [99.8, 99.7, 100, 99.5, 99.9, 100, 99.9],
backgroundColor: 'rgba(255, 123, 37, 0.2)',
borderColor: 'rgba(255, 123, 37, 1)',
borderWidth: 2,
tension: 0.3
}]
};
const events = [
{ type: 'warning', message: 'High response time on API Gateway', time: '10:32 AM' },
{ type: 'error', message: 'Database connection timeout (5 min)', time: 'Yesterday, 3:45 PM' },
{ type: 'info', message: 'Scheduled maintenance completed', time: 'Jun 15, 8:00 AM' },
{ type: 'success', message: 'New server added to cluster', time: 'Jun 14, 1:30 PM' }
];
// Render system status
renderSystems();
// Render uptime chart
renderUptimeChart();
// Render response time chart
renderResponseTimeChart();
// Render events log
renderEvents();
// Form submission
document.getElementById('add-system-form').addEventListener('submit', function(e) {
e.preventDefault();
alert('System added successfully! (This would be connected to your backend in production)');
this.reset();
});
function renderSystems() {
const container = document.getElementById('system-status');
let html = '';
systems.forEach(sys => {
html += `
${sys.name}
${sys.ip}
${sys.status === 'up' ? '🟢 Operational' : '🔴 Down'}
${sys.status === 'up' ? `
${sys.response}ms
` : ''}
`;
});
container.innerHTML = html;
}
function renderUptimeChart() {
const ctx = document.getElementById('uptime-chart');
new Chart(ctx, {
type: 'line',
data: uptimeData,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
tooltip: {
callbacks: {
label: function(context) {
return `${context.dataset.label}: ${context.raw}%`;
}
}
}
},
scales: {
y: {
beginAtZero: false,
min: 95,
max: 100,
ticks: {
callback: function(value) {
return value + '%';
}
}
}
}
}
});
}
function renderResponseTimeChart() {
const options = {
series: [{
name: 'Response Time',
data: systems.filter(s => s.status === 'up').map(s => s.response)
}],
chart: {
height: 180,
type: 'bar',
toolbar: { show: false }
},
colors: [function({ value, seriesIndex, dataPointIndex, w }) {
if (value > 100) return '#FF4560';
if (value > 50) return '#FEB019';
return '#00E396';
}],
plotOptions: {
bar: {
borderRadius: 4,
columnWidth: '60%',
}
},
dataLabels: {
enabled: false
},
xaxis: {
categories: systems.filter(s => s.status === 'up').map(s => s.name),
},
yaxis: {
title: {
text: 'ms',
}
},
tooltip: {
y: {
formatter: function (val) {
return val + " ms"
}
}
}
};
const chart = new ApexCharts(document.querySelector("#response-chart"), options);
chart.render();
}
function renderEvents() {
const container = document.getElementById('events-log');
let html = '';
events.forEach(evt => {
let icon = 'info-circle';
if (evt.type === 'error') icon = 'exclamation-triangle';
if (evt.type === 'warning') icon = 'exclamation-circle';
if (evt.type === 'success') icon = 'check-circle';
html += `
${evt.message}
${evt.time}
`;
});
container.innerHTML = html;
}
// This would be replaced with real API polling in production
setInterval(() => {
// Simulate status changes
const randomSystem = Math.floor(Math.random() * systems.length);
const newStatus = systems[randomSystem].status === 'up' ? 'down' : 'up';
systems[randomSystem].status = newStatus;
renderSystems();
renderResponseTimeChart();
}, 15000);
});