File size: 3,936 Bytes
cf348e9
 
 
 
 
 
67bc35f
cf348e9
67bc35f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf348e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>System Metrics</title>
    <link href="https://fonts.googleapis.com/css2?family=Oswald:wght@400;500&family=Roboto:wght@400;500&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Roboto', sans-serif;
            background-color: #f5f5f5;
            color: #333;
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        h1 {
            text-align: center;
            font-family: 'Oswald', sans-serif;
            font-size: 2.5rem;
            margin: 20px 0;
        }
        .metrics {
            display: flex;
            justify-content: space-around;
            padding: 20px;
            max-width: 1200px;
            margin: 0 auto;
        }
        .metric {
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            width: 30%;
            box-sizing: border-box;
        }
        .metric h2 {
            font-family: 'Oswald', sans-serif;
            font-size: 1.5rem;
            border-bottom: 2px solid #eee;
            padding-bottom: 10px;
            margin-bottom: 15px;
        }
        .metric p {
            font-size: 1.1rem;
            margin: 5px 0;
        }
    </style>
</head>
<body>
    <h1>System Metrics</h1>
    <div class="metrics">
        <div class="metric">
            <h2>CPU Load</h2>
            <p id="cpu-load">Loading...</p>
        </div>
        <div class="metric">
            <h2>Memory Usage</h2>
            <p id="memory-total">Total: Loading...</p>
            <p id="memory-used">Used: Loading...</p>
            <p id="memory-available">Available: Loading...</p>
            <p id="memory-percent">Usage: Loading...</p>
        </div>
        <div class="metric">
            <h2>Disk Usage</h2>
            <p id="disk-total">Total: Loading...</p>
            <p id="disk-used">Used: Loading...</p>
            <p id="disk-free">Free: Loading...</p>
            <p id="disk-percent">Usage: Loading...</p>
        </div>
    </div>
    <script>
        async function fetchMetrics() {
            try {
                const response = await fetch('/system/metrics');
                const metrics = await response.json();
                
                document.getElementById('cpu-load').textContent = metrics.cpu_load + '%';
                
                document.getElementById('memory-total').textContent = 'Total: ' + (metrics.memory.total / (1024 ** 3)).toFixed(2) + ' GB';
                document.getElementById('memory-used').textContent = 'Used: ' + (metrics.memory.used / (1024 ** 3)).toFixed(2) + ' GB';
                document.getElementById('memory-available').textContent = 'Available: ' + (metrics.memory.available / (1024 ** 3)).toFixed(2) + ' GB';
                document.getElementById('memory-percent').textContent = 'Usage: ' + metrics.memory.percent + '%';
                
                document.getElementById('disk-total').textContent = 'Total: ' + (metrics.disk_usage.total / (1024 ** 3)).toFixed(2) + ' GB';
                document.getElementById('disk-used').textContent = 'Used: ' + (metrics.disk_usage.used / (1024 ** 3)).toFixed(2) + ' GB';
                document.getElementById('disk-free').textContent = 'Free: ' + (metrics.disk_usage.free / (1024 ** 3)).toFixed(2) + ' GB';
                document.getElementById('disk-percent').textContent = 'Usage: ' + metrics.disk_usage.percent + '%';
            } catch (error) {
                console.error('Error fetching metrics:', error);
            }
        }
        
        fetchMetrics();
        setInterval(fetchMetrics, 1000); // Refresh metrics every 1 seconds
    </script>
</body>
</html>