-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
131 lines (113 loc) · 5.04 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GPU Board</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<style>
body {
padding-top: 20px;
}
.server-tab {
cursor: pointer;
}
.utilization-0-25 {
background-color: #c8e6c9;
}
.utilization-26-50 {
background-color: #fff59d;
}
.utilization-51-75 {
background-color: #ffcc80;
}
.utilization-76-100 {
background-color: #ef9a9a;
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-center mb-4">GPU Monitor Board</h1>
<ul class="nav nav-tabs" id="serverTabs" role="tablist"></ul>
<div class="tab-content" id="serverTabContent"></div>
</div>
<script>
function getUtilizationClass(utilization) {
if (utilization <= 25) return 'utilization-0-25';
if (utilization <= 50) return 'utilization-26-50';
if (utilization <= 75) return 'utilization-51-75';
return 'utilization-76-100';
}
function updateGPUData() {
fetch('/gpu_data')
.then(response => response.json())
.then(data => {
const tabList = document.getElementById('serverTabs');
const tabContent = document.getElementById('serverTabContent');
tabList.innerHTML = '';
tabContent.innerHTML = '';
Object.entries(data).forEach(([hostname, gpus], index) => {
const tabId = `server-${hostname.replace(/\./g, '-')}`;
// Create tab
const tabItem = document.createElement('li');
tabItem.className = 'nav-item';
tabItem.innerHTML = `
<a class="nav-link ${index === 0 ? 'active' : ''}" id="${tabId}-tab" data-bs-toggle="tab" href="#${tabId}" role="tab">
${hostname}
</a>
`;
tabList.appendChild(tabItem);
// Create tab content
const tabPane = document.createElement('div');
tabPane.className = `tab-pane fade ${index === 0 ? 'show active' : ''}`;
tabPane.id = tabId;
if (gpus.error) {
tabPane.innerHTML = `<p class="text-danger mt-3">Error: ${gpus.error}</p>`;
} else {
let tableContent = `
<table class="table table-striped table-hover mt-3">
<thead>
<tr>
<th>Index</th>
<th>Name</th>
<th>Temperature</th>
<th>Utilization</th>
<th>Memory Used</th>
<th>Memory Total</th>
<th>User</th>
</tr>
</thead>
<tbody>
`;
gpus.forEach(gpu => {
const utilizationClass = getUtilizationClass(parseInt(gpu.utilization));
tableContent += `
<tr class="${utilizationClass}">
<td>${gpu.index}</td>
<td>${gpu.name}</td>
<td>${gpu.temperature}°C</td>
<td>${gpu.utilization}%</td>
<td>${gpu.memory_used} MB</td>
<td>${gpu.memory_total} MB</td>
<td>${gpu.user || 'N/A'}</td>
</tr>
`;
});
tableContent += `
</tbody>
</table>
`;
tabPane.innerHTML = tableContent;
}
tabContent.appendChild(tabPane);
});
});
}
updateGPUData();
setInterval(updateGPUData, 60000); // Update every 60 seconds
</script>
</body>
</html>