File size: 6,258 Bytes
3b38230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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 += `
                <div class="service-item ${sys.status}">
                    <div><strong>${sys.name}</strong></div>
                    <div>${sys.ip}</div>
                    <div>${sys.status === 'up' ? '🟢 Operational' : '🔴 Down'}</div>
                    ${sys.status === 'up' ? `<div>${sys.response}ms</div>` : ''}
                </div>
            `;
        });
        
        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 += `
                <div class="event-item">
                    <div class="event-icon">
                        <i class="fas fa-${icon}"></i>
                    </div>
                    <div class="event-info">
                        <div>${evt.message}</div>
                        <div class="event-time">${evt.time}</div>
                    </div>
                </div>
            `;
        });
        
        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);
});