headscale-tailscale-replace.../farmq-admin/templates/dashboard/index.html
시골약사 11f6ff16d0 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>
2025-09-11 10:38:14 +09:00

299 lines
13 KiB
HTML

{% extends "base.html" %}
{% block title %}대시보드 - 팜큐 약국 관리 시스템{% endblock %}
{% block breadcrumb %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active">
<i class="fas fa-tachometer-alt"></i> 대시보드
</li>
</ol>
</nav>
{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col-12">
<h1 class="h2 mb-0">
<i class="fas fa-tachometer-alt text-primary"></i>
대시보드
</h1>
<p class="text-muted">팜큐 약국 네트워크 전체 현황</p>
</div>
</div>
<!-- 통계 카드 -->
<div class="row mb-4">
<div class="col-lg-3 col-md-6 mb-3">
<div class="card stat-card">
<div class="card-body text-center">
<div class="stat-number" id="total-pharmacies">{{ stats.total_pharmacies }}</div>
<div class="stat-label">
<i class="fas fa-store"></i> 총 약국 수
</div>
</div>
</div>
</div>
<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" data-stat="online">{{ stats.online_machines }}</div>
<div class="stat-label">
<i class="fas fa-circle text-success"></i> 온라인 머신
</div>
</div>
</div>
</div>
<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" data-stat="offline">{{ stats.offline_machines }}</div>
<div class="stat-label">
<i class="fas fa-circle text-danger"></i> 오프라인 머신
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6 mb-3">
<div class="card" style="background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%); color: white;">
<div class="card-body text-center">
<div class="stat-number" id="avg-temp">{{ stats.avg_cpu_temp }}°C</div>
<div class="stat-label">
<i class="fas fa-thermometer-half"></i> 평균 CPU 온도
</div>
</div>
</div>
</div>
</div>
<div class="row">
<!-- 실시간 알림 -->
<div class="col-lg-6 mb-4">
<div class="card h-100">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">
<i class="fas fa-exclamation-triangle text-warning"></i> 실시간 알림
</h5>
<span class="badge bg-primary">{{ stats.alerts|length }}</span>
</div>
<div class="card-body">
{% if stats.alerts %}
{% for alert in stats.alerts %}
<div class="alert-item p-3 mb-2 bg-light {% if alert.type == 'warning' %}alert-warning{% elif alert.type == 'danger' %}alert-danger{% endif %}">
<div class="d-flex justify-content-between align-items-center">
<div>
<strong>
{% if alert.level == 'high_temperature' %}
<i class="fas fa-thermometer-full text-danger"></i>
{% elif alert.level == 'high_disk' %}
<i class="fas fa-hdd text-warning"></i>
{% else %}
<i class="fas fa-exclamation-triangle"></i>
{% endif %}
{{ alert.machine.hostname }}
</strong>
<div class="small text-muted">{{ alert.message }}</div>
</div>
<div class="text-end">
<span class="badge bg-{{ alert.type }}">
{{ alert.value }}{% if alert.level == 'high_temperature' %}°C{% else %}%{% endif %}
</span>
</div>
</div>
</div>
{% endfor %}
{% else %}
<div class="text-center text-muted py-4">
<i class="fas fa-check-circle fa-3x mb-3 text-success"></i>
<p>모든 시스템이 정상 작동 중입니다.</p>
</div>
{% endif %}
</div>
</div>
</div>
<!-- 성능 차트 -->
<div class="col-lg-6 mb-4">
<div class="card h-100">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-chart-pie text-info"></i> 전체 성능 현황
</h5>
</div>
<div class="card-body">
<div class="row text-center">
<div class="col-6 mb-3">
<div class="position-relative">
<canvas id="cpuChart" width="100" height="100"></canvas>
<div class="position-absolute top-50 start-50 translate-middle">
<div class="fw-bold">{{ "%.1f"|format(stats.avg_cpu_temp) }}°C</div>
<div class="small text-muted">CPU</div>
</div>
</div>
</div>
<div class="col-6 mb-3">
<div class="position-relative">
<canvas id="memoryChart" width="100" height="100"></canvas>
<div class="position-absolute top-50 start-50 translate-middle">
<div class="fw-bold">75.0%</div>
<div class="small text-muted">메모리</div>
</div>
</div>
</div>
<div class="col-6">
<div class="position-relative">
<canvas id="diskChart" width="100" height="100"></canvas>
<div class="position-absolute top-50 start-50 translate-middle">
<div class="fw-bold">60.0%</div>
<div class="small text-muted">디스크</div>
</div>
</div>
</div>
<div class="col-6">
<div class="text-center">
<div class="display-4">🌡️</div>
<div class="fw-bold">{{ "%.1f"|format(stats.avg_cpu_temp) }}°C</div>
<div class="small text-muted">평균 온도</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 약국별 상태 -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">
<i class="fas fa-store text-primary"></i> 약국별 상태
</h5>
<a href="{{ url_for('pharmacy_list') }}" class="btn btn-outline-primary btn-sm">
<i class="fas fa-list"></i> 전체 보기
</a>
</div>
<div class="card-body">
{% if pharmacies %}
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>약국명</th>
<th>Headscale 사용자</th>
<th>사업자번호</th>
<th>연결된 머신</th>
<th>온라인 상태</th>
<th>액션</th>
</tr>
</thead>
<tbody>
{% for pharmacy_data in pharmacies %}
<tr>
<td>
<strong>{{ pharmacy_data.pharmacy_name }}</strong><br>
<small class="text-muted">{{ pharmacy_data.manager_name }}</small>
</td>
<td>
<code class="text-primary">{{ pharmacy_data.headscale_user_name }}</code>
</td>
<td>{{ pharmacy_data.business_number }}</td>
<td>
<span class="badge bg-info">{{ pharmacy_data.machine_count }}대</span>
</td>
<td>
<div class="d-flex align-items-center">
<div class="progress me-2" style="width: 100px; height: 8px;">
<div class="progress-bar bg-success"
style="width: {{ (pharmacy_data.online_count / pharmacy_data.machine_count * 100) if pharmacy_data.machine_count > 0 else 0 }}%"></div>
</div>
<small>{{ pharmacy_data.online_count }}/{{ pharmacy_data.machine_count }}</small>
</div>
</td>
<td>
<div class="btn-group btn-group-sm">
<a href="{{ url_for('pharmacy_detail', pharmacy_id=pharmacy_data.id) }}"
class="btn btn-outline-primary">상세</a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center text-muted py-4">
<i class="fas fa-store fa-3x mb-3"></i>
<p>등록된 약국이 없습니다.</p>
<a href="{{ url_for('pharmacy_list') }}" class="btn btn-primary">
<i class="fas fa-plus"></i> 약국 등록하기
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
// 성능 차트 생성
document.addEventListener('DOMContentLoaded', function() {
createDoughnutChart('cpuChart', {{ stats.avg_cpu_temp }}, '온도', '#3b82f6');
createDoughnutChart('memoryChart', 75, '메모리', '#10b981');
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')
.then(response => response.json())
.then(alerts => {
// 알림 개수 업데이트
const alertBadge = document.querySelector('.card-header .badge');
if (alertBadge) {
alertBadge.textContent = alerts.length;
}
// 새로운 알림이 있으면 토스트 표시
alerts.forEach(alert => {
if (!document.querySelector(`[data-machine-id="${alert.machine.id}"]`)) {
showToast(`${alert.machine.hostname}: ${alert.message}`, alert.type);
}
});
})
.catch(error => console.error('Alert update failed:', error));
}
// 통계 업데이트 (10초마다 - 더 자주)
setInterval(updateStats, 10000);
// 알림 업데이트 (30초마다)
setInterval(updateAlerts, 30000);
</script>
{% endblock %}