File size: 15,801 Bytes
16ee433
 
 
 
 
5d3ccc6
 
 
16ee433
 
5d3ccc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16ee433
5d3ccc6
16ee433
5d3ccc6
16ee433
5d3ccc6
 
 
 
 
 
 
16ee433
 
5d3ccc6
 
 
 
 
 
 
16ee433
 
5d3ccc6
 
 
 
16ee433
 
5d3ccc6
 
 
16ee433
 
5d3ccc6
 
 
 
16ee433
 
5d3ccc6
 
16ee433
 
5d3ccc6
 
 
 
16ee433
5d3ccc6
 
 
16ee433
 
5d3ccc6
 
 
 
16ee433
5d3ccc6
 
 
 
 
 
 
 
16ee433
5d3ccc6
 
 
 
 
 
 
 
 
 
 
 
16ee433
5d3ccc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16ee433
 
5d3ccc6
 
 
 
 
 
 
 
 
 
 
 
 
 
16ee433
 
5d3ccc6
 
 
 
 
 
 
 
 
 
 
 
 
 
16ee433
 
5d3ccc6
 
 
 
 
 
 
 
 
 
 
 
 
 
16ee433
 
 
 
 
5d3ccc6
16ee433
 
 
 
 
 
 
 
5d3ccc6
16ee433
5d3ccc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16ee433
 
 
 
 
 
 
5d3ccc6
16ee433
 
5d3ccc6
 
16ee433
 
 
 
5d3ccc6
 
16ee433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d3ccc6
16ee433
 
 
 
 
 
 
 
 
 
 
5d3ccc6
 
 
16ee433
 
5d3ccc6
 
 
 
16ee433
5d3ccc6
 
 
 
 
16ee433
 
 
5d3ccc6
 
 
 
 
 
 
16ee433
 
 
5d3ccc6
16ee433
 
 
5d3ccc6
 
 
 
 
 
 
 
16ee433
 
 
5d3ccc6
16ee433
 
 
5d3ccc6
 
 
16ee433
 
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="zh-TW">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Linux Monitor | System Intelligence</title>
    <!-- Tailwind CSS, Vue 3 & ECharts via CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;600&family=Fira+Sans:wght@300;400;600&display=swap" rel="stylesheet">
    
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        dark: '#0D0D0D',
                        glass: 'rgba(255, 255, 255, 0.05)',
                        'glass-border': 'rgba(255, 255, 255, 0.1)',
                        primary: '#1E40AF',
                        secondary: '#3B82F6',
                        accent: '#F59E0B',
                        success: '#22C55E',
                        danger: '#EF4444',
                        warning: '#F59E0B',
                    },
                    fontFamily: {
                        sans: ['Fira Sans', 'sans-serif'],
                        mono: ['Fira Code', 'monospace'],
                    },
                    animation: {
                        'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite',
                    }
                }
            }
        }
    </script>

    <style>
        body {
            background-color: #0D0D0D;
            color: #E0E0E0;
            font-family: 'Fira Sans', sans-serif;
            background-image: 
                radial-gradient(at 0% 0%, rgba(30, 64, 175, 0.15) 0px, transparent 50%),
                radial-gradient(at 100% 100%, rgba(245, 158, 11, 0.1) 0px, transparent 50%);
            min-height: 100vh;
        }

        .glass-card {
            background: rgba(255, 255, 255, 0.03);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.08);
            box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .glass-card:hover {
            background: rgba(255, 255, 255, 0.06);
            border-color: rgba(255, 255, 255, 0.15);
            transform: translateY(-2px);
        }

        .status-pulse {
            box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
            animation: pulse-green 2s infinite;
        }

        @keyframes pulse-green {
            0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
            70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
            100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
        }

        .status-pulse-red {
            animation: pulse-red 2s infinite;
        }

        @keyframes pulse-red {
            0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
            70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
            100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
        }

        /* ECharts responsiveness */
        .chart-container { width: 100% !important; }
    </style>
</head>
<body class="p-4 md:p-8">
    <div id="app" v-cloak>
        <!-- Header -->
        <header class="flex flex-col md:flex-row justify-between items-start md:items-center mb-8 gap-4">
            <div>
                <h1 class="text-3xl font-bold font-mono tracking-tight text-white flex items-center gap-3">
                    <svg class="size-8 text-secondary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z" />
                    </svg>
                    LINUX_MONITOR
                    <span class="text-xs font-normal px-2 py-0.5 rounded border border-glass-border bg-glass text-gray-400">v1.0.0-PRO</span>
                </h1>
                <p class="text-gray-500 text-sm mt-1 font-sans">Real-time system intelligence and resource analytics</p>
            </div>
            
            <div class="flex items-center gap-4">
                <div class="flex flex-col items-end">
                    <span class="text-[10px] uppercase tracking-widest text-gray-500 font-bold mb-1">System Status</span>
                    <div :class="['flex items-center gap-2 px-3 py-1.5 rounded-full border transition-all duration-500', 
                                 isConnected ? 'bg-success/10 border-success/30 text-success' : 'bg-danger/10 border-danger/30 text-danger']">
                        <span :class="['size-2 rounded-full', isConnected ? 'status-pulse bg-success' : 'status-pulse-red bg-danger']"></span>
                        <span class="text-xs font-bold font-mono uppercase tracking-tighter">{{ isConnected ? 'Live' : 'Offline' }}</span>
                    </div>
                </div>
            </div>
        </header>

        <!-- Bento Grid Dashboard -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
            <!-- CPU Card -->
            <div class="glass-card rounded-2xl p-5 lg:col-span-2">
                <div class="flex justify-between items-center mb-4">
                    <div class="flex items-center gap-3">
                        <div class="p-2 rounded-lg bg-primary/20 text-secondary">
                            <svg class="size-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
                            </svg>
                        </div>
                        <h2 class="font-bold text-white tracking-wide uppercase text-sm font-mono">CPU Utilization</h2>
                    </div>
                    <div class="text-xs font-mono text-gray-500 bg-black/30 px-2 py-1 rounded">60s WINDOW</div>
                </div>
                <div id="cpu-chart" class="chart-container h-[280px]"></div>
            </div>

            <!-- Memory Card -->
            <div class="glass-card rounded-2xl p-5 lg:col-span-2">
                <div class="flex justify-between items-center mb-4">
                    <div class="flex items-center gap-3">
                        <div class="p-2 rounded-lg bg-purple-500/20 text-purple-400">
                            <svg class="size-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17V7m0 10a2 2 0 01-2 2H5a2 2 0 01-2-2V7a2 2 0 012-2h2a2 2 0 012 2m0 10a2 2 0 002 2h2a2 2 0 002-2V7a2 2 0 00-2-2h-2a2 2 0 00-2 2" />
                            </svg>
                        </div>
                        <h2 class="font-bold text-white tracking-wide uppercase text-sm font-mono">Memory Load</h2>
                    </div>
                    <div class="text-xs font-mono text-gray-500 bg-black/30 px-2 py-1 rounded">ECC ENABLED</div>
                </div>
                <div id="mem-chart" class="chart-container h-[280px]"></div>
            </div>

            <!-- Network Card -->
            <div class="glass-card rounded-2xl p-5 lg:col-span-2">
                <div class="flex justify-between items-center mb-4">
                    <div class="flex items-center gap-3">
                        <div class="p-2 rounded-lg bg-success/20 text-success">
                            <svg class="size-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4" />
                            </svg>
                        </div>
                        <h2 class="font-bold text-white tracking-wide uppercase text-sm font-mono">Network Throughput</h2>
                    </div>
                    <div class="text-xs font-mono text-gray-500 bg-black/30 px-2 py-1 rounded">eth0</div>
                </div>
                <div id="net-chart" class="chart-container h-[280px]"></div>
            </div>

            <!-- Disk Card -->
            <div class="glass-card rounded-2xl p-5 lg:col-span-2">
                <div class="flex justify-between items-center mb-4">
                    <div class="flex items-center gap-3">
                        <div class="p-2 rounded-lg bg-warning/20 text-warning">
                            <svg class="size-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H4a2 2 0 00-2 2v7m18 0a2 2 0 01-2 2H4a2 2 0 01-2-2m18 0l-2 2m-2-2l-2 2m-2-2l-2 2m-2-2l-2 2" />
                            </svg>
                        </div>
                        <h2 class="font-bold text-white tracking-wide uppercase text-sm font-mono">Storage I/O</h2>
                    </div>
                    <div class="text-xs font-mono text-gray-500 bg-black/30 px-2 py-1 rounded">NVMe</div>
                </div>
                <div id="disk-chart" class="chart-container h-[280px]"></div>
            </div>
        </div>
    </div>

    <script>
        const { createApp, ref, onMounted } = Vue;

        createApp({
            setup() {
                const isConnected = ref(false);
                let ws = null;
                const charts = {};

                const initChart = (id, title, color) => {
                    const chart = echarts.init(document.getElementById(id), 'dark');
                    chart.setOption({
                        backgroundColor: 'transparent',
                        tooltip: { 
                            trigger: 'axis',
                            backgroundColor: 'rgba(13, 13, 13, 0.9)',
                            borderColor: 'rgba(255, 255, 255, 0.1)',
                            textStyle: { color: '#E0E0E0', fontFamily: 'Fira Code' }
                        },
                        grid: { left: '2%', right: '2%', bottom: '5%', top: '10%', containLabel: true },
                        xAxis: { 
                            type: 'time', 
                            splitLine: { show: false },
                            axisLabel: { color: '#666', fontFamily: 'Fira Code', fontSize: 10 }
                        },
                        yAxis: { 
                            type: 'value', 
                            boundaryGap: [0, '20%'],
                            splitLine: { lineStyle: { color: 'rgba(255, 255, 255, 0.05)' } },
                            axisLabel: { color: '#666', fontFamily: 'Fira Code', fontSize: 10 }
                        },
                        series: [{
                            name: title,
                            type: 'line',
                            smooth: true,
                            showSymbol: false,
                            data: [],
                            itemStyle: { color: color },
                            lineStyle: { width: 3, cap: 'round' },
                            areaStyle: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                    { offset: 0, color: color + '44' }, // 27% opacity
                                    { offset: 1, color: color + '00' }  // 0% opacity
                                ])
                            }
                        }]
                    });
                    
                    window.addEventListener('resize', () => chart.resize());
                    return chart;
                };

                const updateCharts = (metrics) => {
                    const time = metrics.timestamp * 1000;
                    
                    // CPU
                    charts.cpu.setOption({
                        series: [{ data: [...charts.cpu.getOption().series[0].data, [time, metrics.cpu.usage_percent]].slice(-60) }]
                    });

                    // Memory
                    charts.mem.setOption({
                        series: [{ data: [...charts.mem.getOption().series[0].data, [time, metrics.memory.percent]].slice(-60) }]
                    });

                    // Network
                    charts.net.setOption({
                        series: [{ data: [...charts.net.getOption().series[0].data, [time, metrics.network.rx_kbps]].slice(-60) }]
                    });

                    // Disk
                    charts.disk.setOption({
                        series: [{ data: [...charts.disk.getOption().series[0].data, [time, metrics.disk.read_kbps]].slice(-60) }]
                    });
                };

                const handleHistory = (history) => {
                    if (!history || !Array.isArray(history)) return;
                    
                    const cpuData = [], memData = [], netData = [], diskData = [];
                    history.forEach(metrics => {
                        const time = metrics.timestamp * 1000;
                        cpuData.push([time, metrics.cpu.usage_percent]);
                        memData.push([time, metrics.memory.percent]);
                        netData.push([time, metrics.network.rx_kbps]);
                        diskData.push([time, metrics.disk.read_kbps]);
                    });

                    charts.cpu.setOption({ series: [{ data: cpuData.slice(-60) }] });
                    charts.mem.setOption({ series: [{ data: memData.slice(-60) }] });
                    charts.net.setOption({ series: [{ data: netData.slice(-60) }] });
                    charts.disk.setOption({ series: [{ data: diskData.slice(-60) }] });
                };

                onMounted(async () => {
                    // Init Charts with new colors
                    charts.cpu = initChart('cpu-chart', 'CPU Usage', '#3B82F6');
                    charts.mem = initChart('mem-chart', 'Memory Usage', '#A855F7');
                    charts.net = initChart('net-chart', 'Network RX', '#22C55E');
                    charts.disk = initChart('disk-chart', 'Disk Read', '#F59E0B');

                    // Connect WebSocket
                    const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
                    ws = new WebSocket(`${protocol}//${window.location.host}/ws/metrics`);
                    
                    ws.onopen = () => { isConnected.value = true; };
                    ws.onclose = () => { isConnected.value = false; };
                    
                    ws.onmessage = (event) => {
                        try {
                            const data = JSON.parse(event.data);
                            if (Array.isArray(data)) {
                                handleHistory(data);
                            } else {
                                updateCharts(data);
                            }
                        } catch (e) { console.error("WS parse error", e); }
                    };
                });

                return { isConnected };
            }
        }).mount('#app');
    </script>
    <style>
        [v-cloak] { display: none; }
    </style>
</body>
</html>