Implement real-time online status synchronization with Headplane

- Add Headscale CLI integration to get real-time online status
- Replace timeout-based logic with exact same logic as Headplane
- Use 'online' field from Headscale CLI JSON output
- Update dashboard statistics to show 3 online nodes matching Headplane
- Update pharmacy and machine management views with real-time status

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-11 10:38:14 +09:00
parent 1f0afd4cae
commit 11f6ff16d0
2 changed files with 91 additions and 39 deletions

View File

@@ -39,7 +39,7 @@
<div class="col-lg-3 col-md-6 mb-3">
<div class="card" style="background: linear-gradient(135deg, #48bb78 0%, #38a169 100%); color: white;">
<div class="card-body text-center">
<div class="stat-number" id="online-machines">{{ stats.online_machines }}</div>
<div class="stat-number" id="online-machines" data-stat="online">{{ stats.online_machines }}</div>
<div class="stat-label">
<i class="fas fa-circle text-success"></i> 온라인 머신
</div>
@@ -50,7 +50,7 @@
<div class="col-lg-3 col-md-6 mb-3">
<div class="card" style="background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%); color: white;">
<div class="card-body text-center">
<div class="stat-number" id="offline-machines">{{ stats.offline_machines }}</div>
<div class="stat-number" id="offline-machines" data-stat="offline">{{ stats.offline_machines }}</div>
<div class="stat-label">
<i class="fas fa-circle text-danger"></i> 오프라인 머신
</div>
@@ -250,6 +250,26 @@ document.addEventListener('DOMContentLoaded', function() {
createDoughnutChart('diskChart', 60, '디스크', '#f59e0b');
});
// 실시간 통계 업데이트
function updateStats() {
fetch('/api/dashboard/stats')
.then(response => response.json())
.then(stats => {
// 머신 상태 업데이트
const onlineElement = document.querySelector('[data-stat="online"]');
const offlineElement = document.querySelector('[data-stat="offline"]');
const totalElement = document.querySelector('[data-stat="total"]');
if (onlineElement) onlineElement.textContent = stats.online_machines;
if (offlineElement) offlineElement.textContent = stats.offline_machines;
if (totalElement) totalElement.textContent = stats.total_machines;
// CPU 온도 차트 업데이트
updateChartValue('cpuChart', stats.avg_cpu_temp);
})
.catch(error => console.error('Stats update failed:', error));
}
// 실시간 알림 업데이트
function updateAlerts() {
fetch('/api/alerts')
@@ -271,6 +291,8 @@ function updateAlerts() {
.catch(error => console.error('Alert update failed:', error));
}
// 통계 업데이트 (10초마다 - 더 자주)
setInterval(updateStats, 10000);
// 알림 업데이트 (30초마다)
setInterval(updateAlerts, 30000);
</script>