feat: basic cluster overview

This commit is contained in:
2025-08-24 21:08:40 +02:00
commit 4ab19e9ded
616 changed files with 69980 additions and 0 deletions

306
public/index.html Normal file
View File

@@ -0,0 +1,306 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SPORE UI</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 2rem;
color: white;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
text-align: center;
margin-bottom: 3rem;
}
h1 {
font-size: 3rem;
margin-bottom: 1rem;
font-weight: 700;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
p {
font-size: 1.2rem;
opacity: 0.9;
margin-bottom: 2rem;
}
.status {
background: rgba(255, 255, 255, 0.2);
padding: 1rem 2rem;
border-radius: 50px;
font-weight: 500;
display: inline-block;
margin-bottom: 2rem;
}
.cluster-section {
background: rgba(255, 255, 255, 0.1);
border-radius: 20px;
backdrop-filter: blur(10px);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
padding: 2rem;
margin-bottom: 2rem;
}
.cluster-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.cluster-title {
font-size: 1.5rem;
font-weight: 600;
}
.refresh-btn {
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.3);
color: white;
padding: 0.5rem 1rem;
border-radius: 8px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.3s ease;
}
.refresh-btn:hover {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-2px);
}
.refresh-btn:active {
transform: translateY(0);
}
.members-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 1rem;
}
.member-card {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 12px;
padding: 1.5rem;
transition: all 0.3s ease;
}
.member-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}
.member-name {
font-size: 1.2rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: #fff;
}
.member-ip {
font-size: 0.9rem;
opacity: 0.8;
margin-bottom: 0.5rem;
font-family: 'Courier New', monospace;
}
.member-status {
display: inline-block;
padding: 0.25rem 0.75rem;
border-radius: 20px;
font-size: 0.8rem;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.status-online {
background: rgba(76, 175, 80, 0.3);
color: #4caf50;
border: 1px solid rgba(76, 175, 80, 0.5);
}
.status-offline {
background: rgba(244, 67, 54, 0.3);
color: #f44336;
border: 1px solid rgba(244, 67, 54, 0.5);
}
.loading {
text-align: center;
padding: 2rem;
opacity: 0.7;
}
.error {
background: rgba(244, 67, 54, 0.2);
border: 1px solid rgba(244, 67, 54, 0.3);
color: #ffcdd2;
padding: 1rem;
border-radius: 8px;
margin-top: 1rem;
}
.empty-state {
text-align: center;
padding: 2rem;
opacity: 0.7;
}
.empty-state-icon {
font-size: 3rem;
margin-bottom: 1rem;
opacity: 0.5;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>SPORE UI</h1>
<div class="status">🚀 Cluster Online</div>
</div>
<div class="cluster-section">
<div class="cluster-header">
<div class="cluster-title">🌐 Cluster Members</div>
<button class="refresh-btn" onclick="refreshClusterMembers()">
🔄 Refresh
</button>
</div>
<div id="cluster-members-container">
<div class="loading">
<div>Loading cluster members...</div>
</div>
</div>
</div>
</div>
<script>
// Frontend API client - calls our Express backend
class FrontendApiClient {
constructor() {
this.baseUrl = ''; // Same origin as the current page
}
async getClusterMembers() {
try {
const response = await fetch('/api/cluster/members', {
method: 'GET',
headers: {
'Accept': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
} catch (error) {
throw new Error(`Request failed: ${error.message}`);
}
}
}
// Global client instance
const client = new FrontendApiClient();
// Function to refresh cluster members
async function refreshClusterMembers() {
const container = document.getElementById('cluster-members-container');
// Show loading state
container.innerHTML = `
<div class="loading">
<div>Loading cluster members...</div>
</div>
`;
try {
const response = await client.getClusterMembers();
console.log(response);
displayClusterMembers(response.members);
} catch (error) {
console.error('Failed to fetch cluster members:', error);
container.innerHTML = `
<div class="error">
<strong>Error loading cluster members:</strong><br>
${error.message}
</div>
`;
}
}
// Function to display cluster members
function displayClusterMembers(members) {
const container = document.getElementById('cluster-members-container');
if (!members || members.length === 0) {
container.innerHTML = `
<div class="empty-state">
<div class="empty-state-icon">🌐</div>
<div>No cluster members found</div>
<div style="font-size: 0.9rem; margin-top: 0.5rem; opacity: 0.7;">
The cluster might be empty or not yet discovered
</div>
</div>
`;
return;
}
const membersHTML = members.map(member => {
const statusClass = member.status === 'active' ? 'status-online' : 'status-offline';
const statusText = member.status === 'active' ? 'Online' : 'Offline';
const statusIcon = member.status === 'active' ? '🟢' : '🔴';
return `
<div class="member-card">
<div class="member-name">${member.hostname || 'Unknown Device'}</div>
<div class="member-ip">${member.ip || 'No IP'}</div>
<div class="member-status ${statusClass}">
${statusIcon} ${statusText}
</div>
<div style="font-size: 0.8rem; opacity: 0.7; margin-top: 0.5rem;">
Latency: ${member.latency}ms | Heap: ${Math.round(member.resources?.freeHeap / 1024)}KB
</div>
</div>
`;
}).join('');
container.innerHTML = membersHTML;
}
// Load cluster members when page loads
document.addEventListener('DOMContentLoaded', function() {
refreshClusterMembers();
});
// Auto-refresh every 30 seconds
setInterval(refreshClusterMembers, 30000);
</script>
</body>
</html>