cluster_volume_servers.templ 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. package app
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/admin/dash"
  5. )
  6. templ ClusterVolumeServers(data dash.ClusterVolumeServersData) {
  7. <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
  8. <h1 class="h2">
  9. <i class="fas fa-server me-2"></i>Volume Servers
  10. </h1>
  11. <div class="btn-toolbar mb-2 mb-md-0">
  12. <div class="btn-group me-2">
  13. <button type="button" class="btn btn-sm btn-outline-primary" onclick="exportVolumeServers()">
  14. <i class="fas fa-download me-1"></i>Export
  15. </button>
  16. </div>
  17. </div>
  18. </div>
  19. <div id="hosts-content">
  20. <!-- Summary Cards -->
  21. <div class="row mb-4">
  22. <div class="col-xl-3 col-md-6 mb-4">
  23. <div class="card border-left-primary shadow h-100 py-2">
  24. <div class="card-body">
  25. <div class="row no-gutters align-items-center">
  26. <div class="col mr-2">
  27. <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
  28. Total Volume Servers
  29. </div>
  30. <div class="h5 mb-0 font-weight-bold text-gray-800">
  31. {fmt.Sprintf("%d", data.TotalVolumeServers)}
  32. </div>
  33. </div>
  34. <div class="col-auto">
  35. <i class="fas fa-server fa-2x text-gray-300"></i>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="col-xl-3 col-md-6 mb-4">
  42. <div class="card border-left-info shadow h-100 py-2">
  43. <div class="card-body">
  44. <div class="row no-gutters align-items-center">
  45. <div class="col mr-2">
  46. <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
  47. Total Volumes
  48. </div>
  49. <div class="h5 mb-0 font-weight-bold text-gray-800">
  50. {fmt.Sprintf("%d", data.TotalVolumes)}
  51. </div>
  52. </div>
  53. <div class="col-auto">
  54. <i class="fas fa-database fa-2x text-gray-300"></i>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="col-xl-3 col-md-6 mb-4">
  61. <div class="card border-left-warning shadow h-100 py-2">
  62. <div class="card-body">
  63. <div class="row no-gutters align-items-center">
  64. <div class="col mr-2">
  65. <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
  66. Total Capacity
  67. </div>
  68. <div class="h5 mb-0 font-weight-bold text-gray-800">
  69. {formatBytes(data.TotalCapacity)}
  70. </div>
  71. </div>
  72. <div class="col-auto">
  73. <i class="fas fa-hdd fa-2x text-gray-300"></i>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <!-- Hosts Table -->
  81. <div class="card shadow mb-4">
  82. <div class="card-header py-3">
  83. <h6 class="m-0 font-weight-bold text-primary">
  84. <i class="fas fa-server me-2"></i>Volume Servers
  85. </h6>
  86. </div>
  87. <div class="card-body">
  88. if len(data.VolumeServers) > 0 {
  89. <div class="table-responsive">
  90. <table class="table table-hover" id="hostsTable">
  91. <thead>
  92. <tr>
  93. <th>Address</th>
  94. <th>Data Center</th>
  95. <th>Rack</th>
  96. <th>Volumes</th>
  97. <th>Max Volumes</th>
  98. <th>EC Shards</th>
  99. <th>Capacity</th>
  100. <th>Usage</th>
  101. <th>Actions</th>
  102. </tr>
  103. </thead>
  104. <tbody>
  105. for _, host := range data.VolumeServers {
  106. <tr>
  107. <td>
  108. <a href={templ.SafeURL(fmt.Sprintf("http://%s/ui/index.html", host.PublicURL))} target="_blank" class="text-decoration-none">
  109. {host.Address}
  110. <i class="fas fa-external-link-alt ms-1 text-muted"></i>
  111. </a>
  112. </td>
  113. <td>
  114. <span class="badge bg-light text-dark">{host.DataCenter}</span>
  115. </td>
  116. <td>
  117. <span class="badge bg-light text-dark">{host.Rack}</span>
  118. </td>
  119. <td>
  120. <div class="d-flex align-items-center">
  121. <div class="progress me-2" style="width: 60px; height: 16px;">
  122. <div class="progress-bar" role="progressbar"
  123. style={fmt.Sprintf("width: %d%%", calculatePercent(host.Volumes, host.MaxVolumes))}>
  124. </div>
  125. </div>
  126. <span class="badge bg-primary">{fmt.Sprintf("%d", host.Volumes)}</span>
  127. </div>
  128. </td>
  129. <td>
  130. <span class="badge bg-secondary">{fmt.Sprintf("%d", host.MaxVolumes)}</span>
  131. </td>
  132. <td>
  133. if host.EcShards > 0 {
  134. <div class="d-flex align-items-center">
  135. <i class="fas fa-layer-group me-1 text-info"></i>
  136. <span class="badge bg-info text-white me-1">{fmt.Sprintf("%d", host.EcShards)}</span>
  137. <small class="text-muted">shards</small>
  138. </div>
  139. if host.EcVolumes > 0 {
  140. <div class="mt-1">
  141. <small class="text-muted">{fmt.Sprintf("%d EC volumes", host.EcVolumes)}</small>
  142. </div>
  143. }
  144. } else {
  145. <span class="text-muted">-</span>
  146. }
  147. </td>
  148. <td>{formatBytes(host.DiskCapacity)}</td>
  149. <td>
  150. <div class="d-flex align-items-center">
  151. <div class="progress me-2" style="width: 60px; height: 16px;">
  152. <div class="progress-bar" role="progressbar"
  153. style={fmt.Sprintf("width: %d%%", calculatePercent(int(host.DiskUsage), int(host.DiskCapacity)))}>
  154. </div>
  155. </div>
  156. <small>{formatBytes(host.DiskUsage)}</small>
  157. </div>
  158. </td>
  159. <td>
  160. <button type="button"
  161. class="btn btn-outline-primary btn-sm"
  162. title="View Details"
  163. data-action="view-details"
  164. data-id={host.ID}
  165. data-address={host.Address}
  166. data-public-url={host.PublicURL}
  167. data-datacenter={host.DataCenter}
  168. data-rack={host.Rack}
  169. data-volumes={fmt.Sprintf("%d", host.Volumes)}
  170. data-max-volumes={fmt.Sprintf("%d", host.MaxVolumes)}
  171. data-disk-usage={fmt.Sprintf("%d", host.DiskUsage)}
  172. data-disk-capacity={fmt.Sprintf("%d", host.DiskCapacity)}
  173. data-ec-volumes={fmt.Sprintf("%d", host.EcVolumes)}
  174. data-ec-shards={fmt.Sprintf("%d", host.EcShards)}
  175. data-last-heartbeat={host.LastHeartbeat.Format("2006-01-02 15:04:05")}>
  176. <i class="fas fa-eye"></i>
  177. </button>
  178. </td>
  179. </tr>
  180. }
  181. </tbody>
  182. </table>
  183. </div>
  184. } else {
  185. <div class="text-center py-5">
  186. <i class="fas fa-server fa-3x text-muted mb-3"></i>
  187. <h5 class="text-muted">No Volume Servers Found</h5>
  188. <p class="text-muted">No volume servers are currently available in the cluster.</p>
  189. </div>
  190. }
  191. </div>
  192. </div>
  193. <!-- Last Updated -->
  194. <div class="row">
  195. <div class="col-12">
  196. <small class="text-muted">
  197. <i class="fas fa-clock me-1"></i>
  198. Last updated: {data.LastUpdated.Format("2006-01-02 15:04:05")}
  199. </small>
  200. </div>
  201. </div>
  202. </div>
  203. <!-- JavaScript for cluster volume servers functionality -->
  204. <script>
  205. document.addEventListener('DOMContentLoaded', function() {
  206. // Handle volume server action buttons
  207. document.addEventListener('click', function(e) {
  208. const button = e.target.closest('[data-action]');
  209. if (!button) return;
  210. const action = button.getAttribute('data-action');
  211. switch(action) {
  212. case 'view-details':
  213. const serverData = {
  214. id: button.getAttribute('data-id'),
  215. address: button.getAttribute('data-address'),
  216. publicUrl: button.getAttribute('data-public-url'),
  217. datacenter: button.getAttribute('data-datacenter'),
  218. rack: button.getAttribute('data-rack'),
  219. volumes: parseInt(button.getAttribute('data-volumes')),
  220. maxVolumes: parseInt(button.getAttribute('data-max-volumes')),
  221. diskUsage: parseInt(button.getAttribute('data-disk-usage')),
  222. diskCapacity: parseInt(button.getAttribute('data-disk-capacity')),
  223. ecVolumes: parseInt(button.getAttribute('data-ec-volumes')),
  224. ecShards: parseInt(button.getAttribute('data-ec-shards')),
  225. lastHeartbeat: button.getAttribute('data-last-heartbeat')
  226. };
  227. showVolumeServerDetails(serverData);
  228. break;
  229. }
  230. });
  231. });
  232. function showVolumeServerDetails(server) {
  233. const volumePercent = server.maxVolumes > 0 ? Math.round((server.volumes / server.maxVolumes) * 100) : 0;
  234. const diskPercent = server.diskCapacity > 0 ? Math.round((server.diskUsage / server.diskCapacity) * 100) : 0;
  235. const modalHtml = '<div class="modal fade" id="volumeServerDetailsModal" tabindex="-1">' +
  236. '<div class="modal-dialog modal-lg">' +
  237. '<div class="modal-content">' +
  238. '<div class="modal-header">' +
  239. '<h5 class="modal-title"><i class="fas fa-server me-2"></i>Volume Server Details: ' + server.address + '</h5>' +
  240. '<button type="button" class="btn-close" data-bs-dismiss="modal"></button>' +
  241. '</div>' +
  242. '<div class="modal-body">' +
  243. '<div class="row">' +
  244. '<div class="col-md-6">' +
  245. '<h6 class="text-primary"><i class="fas fa-info-circle me-1"></i>Basic Information</h6>' +
  246. '<table class="table table-sm">' +
  247. '<tr><td><strong>Server ID:</strong></td><td><code>' + server.id + '</code></td></tr>' +
  248. '<tr><td><strong>Address:</strong></td><td>' + server.address + '</td></tr>' +
  249. '<tr><td><strong>Public URL:</strong></td><td>' + server.publicUrl + '</td></tr>' +
  250. '<tr><td><strong>Data Center:</strong></td><td><span class="badge bg-light text-dark">' + server.datacenter + '</span></td></tr>' +
  251. '<tr><td><strong>Rack:</strong></td><td><span class="badge bg-light text-dark">' + server.rack + '</span></td></tr>' +
  252. '<tr><td><strong>Last Heartbeat:</strong></td><td>' + server.lastHeartbeat + '</td></tr>' +
  253. '</table>' +
  254. '</div>' +
  255. '<div class="col-md-6">' +
  256. '<h6 class="text-primary"><i class="fas fa-chart-bar me-1"></i>Usage Statistics</h6>' +
  257. '<table class="table table-sm">' +
  258. '<tr><td><strong>Volumes:</strong></td><td>' +
  259. '<div class="d-flex align-items-center">' +
  260. '<div class="progress me-2" style="width: 100px; height: 20px;">' +
  261. '<div class="progress-bar" role="progressbar" style="width: ' + volumePercent + '%"></div>' +
  262. '</div>' +
  263. '<span>' + server.volumes + '/' + server.maxVolumes + ' (' + volumePercent + '%)</span>' +
  264. '</div>' +
  265. '</td></tr>' +
  266. '<tr><td><strong>Disk Usage:</strong></td><td>' +
  267. '<div class="d-flex align-items-center">' +
  268. '<div class="progress me-2" style="width: 100px; height: 20px;">' +
  269. '<div class="progress-bar" role="progressbar" style="width: ' + diskPercent + '%"></div>' +
  270. '</div>' +
  271. '<span>' + formatBytes(server.diskUsage) + '/' + formatBytes(server.diskCapacity) + ' (' + diskPercent + '%)</span>' +
  272. '</div>' +
  273. '</td></tr>' +
  274. '<tr><td><strong>Available Space:</strong></td><td>' + formatBytes(server.diskCapacity - server.diskUsage) + '</td></tr>' +
  275. '</table>' +
  276. '</div>' +
  277. '</div>' +
  278. // Add EC Shard information if available
  279. (server.ecShards > 0 ?
  280. '<div class="row mt-3">' +
  281. '<div class="col-12">' +
  282. '<h6 class="text-primary"><i class="fas fa-layer-group me-1"></i>Erasure Coding Information</h6>' +
  283. '<table class="table table-sm">' +
  284. '<tr><td><strong>EC Volumes:</strong></td><td><span class="badge bg-info text-white">' + server.ecVolumes + '</span></td></tr>' +
  285. '<tr><td><strong>EC Shards:</strong></td><td><span class="badge bg-info text-white">' + server.ecShards + '</span></td></tr>' +
  286. '</table>' +
  287. '</div>' +
  288. '</div>' : '') +
  289. '<div class="row mt-3">' +
  290. '<div class="col-12">' +
  291. '<h6 class="text-primary"><i class="fas fa-link me-1"></i>Quick Actions</h6>' +
  292. '<div class="d-grid gap-2 d-md-flex">' +
  293. '<a href="http://' + server.publicUrl + '/ui/index.html" target="_blank" class="btn btn-outline-primary">' +
  294. '<i class="fas fa-external-link-alt me-1"></i>Open Volume Server UI' +
  295. '</a>' +
  296. '<a href="/cluster/volumes?server=' + encodeURIComponent(server.address) + '" class="btn btn-outline-info">' +
  297. '<i class="fas fa-database me-1"></i>View Volumes' +
  298. '</a>' +
  299. '</div>' +
  300. '</div>' +
  301. '</div>' +
  302. '</div>' +
  303. '<div class="modal-footer">' +
  304. '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>' +
  305. '</div>' +
  306. '</div>' +
  307. '</div>' +
  308. '</div>';
  309. // Remove existing modal if present
  310. const existingModal = document.getElementById('volumeServerDetailsModal');
  311. if (existingModal) {
  312. existingModal.remove();
  313. }
  314. // Add modal to body and show
  315. document.body.insertAdjacentHTML('beforeend', modalHtml);
  316. const modal = new bootstrap.Modal(document.getElementById('volumeServerDetailsModal'));
  317. modal.show();
  318. // Remove modal when hidden
  319. document.getElementById('volumeServerDetailsModal').addEventListener('hidden.bs.modal', function() {
  320. this.remove();
  321. });
  322. }
  323. function formatBytes(bytes) {
  324. if (bytes === 0) return '0 Bytes';
  325. const k = 1024;
  326. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  327. const i = Math.floor(Math.log(bytes) / Math.log(k));
  328. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  329. }
  330. function exportVolumeServers() {
  331. // Simple CSV export of volume servers list
  332. const rows = Array.from(document.querySelectorAll('#hostsTable tbody tr')).map(row => {
  333. const cells = row.querySelectorAll('td');
  334. if (cells.length > 1) {
  335. return {
  336. id: cells[0].textContent.trim(),
  337. address: cells[1].textContent.trim(),
  338. datacenter: cells[2].textContent.trim(),
  339. rack: cells[3].textContent.trim(),
  340. volumes: cells[4].textContent.trim(),
  341. capacity: cells[5].textContent.trim(),
  342. usage: cells[6].textContent.trim()
  343. };
  344. }
  345. return null;
  346. }).filter(row => row !== null);
  347. const csvContent = "data:text/csv;charset=utf-8," +
  348. "Server ID,Address,Data Center,Rack,Volumes,Capacity,Usage\n" +
  349. rows.map(r => '"' + r.id + '","' + r.address + '","' + r.datacenter + '","' + r.rack + '","' + r.volumes + '","' + r.capacity + '","' + r.usage + '"').join("\n");
  350. const encodedUri = encodeURI(csvContent);
  351. const link = document.createElement("a");
  352. link.setAttribute("href", encodedUri);
  353. link.setAttribute("download", "volume_servers.csv");
  354. document.body.appendChild(link);
  355. link.click();
  356. document.body.removeChild(link);
  357. }
  358. </script>
  359. }