Files
ai-server/integrations/document-ai/templates/dashboard.html

585 lines
19 KiB
HTML

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI 모델 대시보드 - NLLB 번역 시스템</title>
<style>
:root {
--primary-color: #2563eb;
--success-color: #059669;
--warning-color: #d97706;
--error-color: #dc2626;
--background-color: #f8fafc;
--text-color: #1e293b;
--border-color: #e2e8f0;
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
line-height: 1.6;
color: var(--text-color);
background: var(--background-color);
}
.dashboard-container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
.header {
background: white;
border-radius: 12px;
padding: 24px;
margin-bottom: 24px;
box-shadow: var(--shadow);
border: 1px solid var(--border-color);
}
.header h1 {
font-size: 2rem;
font-weight: 700;
color: var(--primary-color);
margin-bottom: 8px;
}
.header .subtitle {
color: #64748b;
font-size: 1.1rem;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
gap: 24px;
margin-bottom: 24px;
}
.card {
background: white;
border-radius: 12px;
padding: 24px;
box-shadow: var(--shadow);
border: 1px solid var(--border-color);
}
.card-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 20px;
padding-bottom: 12px;
border-bottom: 1px solid var(--border-color);
}
.card-header h3 {
font-size: 1.25rem;
font-weight: 600;
color: var(--text-color);
}
.card-icon {
font-size: 1.5rem;
}
.model-status {
display: flex;
flex-direction: column;
gap: 16px;
}
.model-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px;
background: #f8fafc;
border-radius: 8px;
border: 1px solid var(--border-color);
}
.model-info h4 {
font-weight: 600;
margin-bottom: 4px;
}
.model-details {
font-size: 0.875rem;
color: #64748b;
}
.status-badge {
padding: 6px 12px;
border-radius: 20px;
font-size: 0.75rem;
font-weight: 600;
text-transform: uppercase;
}
.status-ready {
background: #dcfce7;
color: var(--success-color);
}
.status-loading {
background: #fef3c7;
color: var(--warning-color);
}
.status-error {
background: #fee2e2;
color: var(--error-color);
}
.status-unloaded {
background: #f1f5f9;
color: #64748b;
}
.metrics-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 16px;
}
.metric-item {
text-align: center;
padding: 16px;
background: #f8fafc;
border-radius: 8px;
}
.metric-value {
font-size: 2rem;
font-weight: 700;
color: var(--primary-color);
margin-bottom: 4px;
}
.metric-label {
font-size: 0.875rem;
color: #64748b;
}
.progress-bar {
width: 100%;
height: 8px;
background: #e2e8f0;
border-radius: 4px;
overflow: hidden;
margin: 8px 0;
}
.progress-fill {
height: 100%;
background: var(--primary-color);
transition: width 0.3s ease;
}
.control-buttons {
display: flex;
gap: 12px;
margin-top: 20px;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
font-size: 0.875rem;
}
.btn-primary {
background: var(--primary-color);
color: white;
}
.btn-primary:hover {
background: #1d4ed8;
}
.btn-secondary {
background: #64748b;
color: white;
}
.btn-secondary:hover {
background: #475569;
}
.job-list {
max-height: 300px;
overflow-y: auto;
}
.job-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 0;
border-bottom: 1px solid var(--border-color);
}
.job-item:last-child {
border-bottom: none;
}
.job-id {
font-family: monospace;
font-size: 0.75rem;
color: #64748b;
}
.auto-refresh {
position: fixed;
top: 20px;
right: 20px;
background: white;
padding: 12px;
border-radius: 8px;
box-shadow: var(--shadow);
border: 1px solid var(--border-color);
}
.refresh-indicator {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--success-color);
margin-right: 8px;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.chart-container {
height: 200px;
position: relative;
margin-top: 16px;
}
@media (max-width: 768px) {
.dashboard-container {
padding: 12px;
}
.grid {
grid-template-columns: 1fr;
}
.metrics-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="auto-refresh">
<div style="display: flex; align-items: center;">
<div class="refresh-indicator"></div>
<span style="font-size: 0.875rem;">실시간 업데이트</span>
</div>
</div>
<div class="dashboard-container">
<div class="header">
<h1>🤖 AI 모델 대시보드</h1>
<p class="subtitle">NLLB 번역 시스템 - 실시간 모니터링</p>
</div>
<div class="grid">
<!-- 모델 상태 카드 -->
<div class="card">
<div class="card-header">
<span class="card-icon">🧠</span>
<h3>AI 모델 상태</h3>
</div>
<div class="model-status" id="modelStatus">
<!-- 동적으로 채워짐 -->
</div>
<div class="control-buttons">
<button class="btn btn-primary" onclick="restartModels()">
🔄 모델 재시작
</button>
<button class="btn btn-secondary" onclick="clearCache()">
🗑️ 캐시 정리
</button>
</div>
</div>
<!-- 시스템 성능 카드 -->
<div class="card">
<div class="card-header">
<span class="card-icon">📊</span>
<h3>시스템 성능</h3>
</div>
<div class="metrics-grid" id="systemMetrics">
<!-- 동적으로 채워짐 -->
</div>
</div>
<!-- 작업 통계 카드 -->
<div class="card">
<div class="card-header">
<span class="card-icon">📈</span>
<h3>작업 통계</h3>
</div>
<div class="metrics-grid" id="jobStats">
<!-- 동적으로 채워짐 -->
</div>
<div class="chart-container">
<canvas id="performanceChart" width="400" height="200"></canvas>
</div>
</div>
<!-- 활성 작업 카드 -->
<div class="card">
<div class="card-header">
<span class="card-icon"></span>
<h3>활성 작업</h3>
</div>
<div class="job-list" id="activeJobs">
<!-- 동적으로 채워짐 -->
</div>
</div>
</div>
</div>
<script>
// 대시보드 데이터 관리
let dashboardData = {};
let performanceChart = null;
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', function() {
initializeChart();
loadDashboardData();
// 5초마다 자동 새로고침
setInterval(loadDashboardData, 5000);
});
// 대시보드 데이터 로드
async function loadDashboardData() {
try {
const response = await fetch('/api/dashboard');
dashboardData = await response.json();
updateModelStatus();
updateSystemMetrics();
updateJobStats();
updateActiveJobs();
updatePerformanceChart();
} catch (error) {
console.error('대시보드 데이터 로드 실패:', error);
}
}
// 모델 상태 업데이트
function updateModelStatus() {
const container = document.getElementById('modelStatus');
container.innerHTML = '';
if (dashboardData.models_status) {
Object.values(dashboardData.models_status).forEach(model => {
const modelItem = document.createElement('div');
modelItem.className = 'model-item';
const memoryUsage = model.memory_usage_mb ? `${model.memory_usage_mb.toFixed(0)}MB` : 'N/A';
const totalProcessed = model.total_processed || 0;
const lastUsed = model.last_used ? new Date(model.last_used).toLocaleTimeString() : 'N/A';
modelItem.innerHTML = `
<div class="model-info">
<h4>${model.name}</h4>
<div class="model-details">
메모리: ${memoryUsage} | 처리 완료: ${totalProcessed}개 | 마지막 사용: ${lastUsed}
</div>
</div>
<span class="status-badge status-${model.status}">${getStatusText(model.status)}</span>
`;
container.appendChild(modelItem);
});
}
}
// 시스템 메트릭 업데이트
function updateSystemMetrics() {
const container = document.getElementById('systemMetrics');
container.innerHTML = '';
if (dashboardData.current_metrics) {
const metrics = dashboardData.current_metrics;
const metricItems = [
{ value: `${metrics.total_memory_usage_mb.toFixed(0)}MB`, label: '메모리 사용량' },
{ value: `${metrics.cpu_usage_percent.toFixed(1)}%`, label: 'CPU 사용률' },
{ value: formatUptime(metrics.uptime_seconds), label: '서비스 가동시간' },
{ value: `${metrics.average_processing_time.toFixed(1)}`, label: '평균 처리시간' }
];
metricItems.forEach(item => {
const metricDiv = document.createElement('div');
metricDiv.className = 'metric-item';
metricDiv.innerHTML = `
<div class="metric-value">${item.value}</div>
<div class="metric-label">${item.label}</div>
`;
container.appendChild(metricDiv);
});
}
}
// 작업 통계 업데이트
function updateJobStats() {
const container = document.getElementById('jobStats');
container.innerHTML = '';
if (dashboardData.current_metrics) {
const metrics = dashboardData.current_metrics;
const jobItems = [
{ value: metrics.active_jobs, label: '진행 중인 작업' },
{ value: metrics.queued_jobs, label: '대기 중인 작업' },
{ value: metrics.completed_jobs_today, label: '오늘 완료된 작업' },
{ value: dashboardData.completed_today || 0, label: '총 완료 작업' }
];
jobItems.forEach(item => {
const jobDiv = document.createElement('div');
jobDiv.className = 'metric-item';
jobDiv.innerHTML = `
<div class="metric-value">${item.value}</div>
<div class="metric-label">${item.label}</div>
`;
container.appendChild(jobDiv);
});
}
}
// 활성 작업 업데이트
function updateActiveJobs() {
const container = document.getElementById('activeJobs');
if (dashboardData.active_jobs === 0) {
container.innerHTML = '<div style="text-align: center; color: #64748b; padding: 20px;">현재 진행 중인 작업이 없습니다.</div>';
} else {
container.innerHTML = `<div style="text-align: center; color: #2563eb; padding: 20px;">현재 ${dashboardData.active_jobs}개의 작업이 진행 중입니다.</div>`;
}
}
// 성능 차트 초기화
function initializeChart() {
const canvas = document.getElementById('performanceChart');
const ctx = canvas.getContext('2d');
// 간단한 차트 구현 (실제로는 Chart.js 등 사용 권장)
performanceChart = {
canvas: canvas,
ctx: ctx,
data: []
};
}
// 성능 차트 업데이트
function updatePerformanceChart() {
if (!performanceChart || !dashboardData.recent_metrics) return;
const ctx = performanceChart.ctx;
const canvas = performanceChart.canvas;
// 캔버스 지우기
ctx.clearRect(0, 0, canvas.width, canvas.height);
// 간단한 메모리 사용량 그래프 그리기
const metrics = dashboardData.recent_metrics.slice(-20); // 최근 20개
if (metrics.length === 0) return;
const maxMemory = Math.max(...metrics.map(m => m.metrics.total_memory_usage_mb));
const width = canvas.width;
const height = canvas.height;
ctx.strokeStyle = '#2563eb';
ctx.lineWidth = 2;
ctx.beginPath();
metrics.forEach((metric, index) => {
const x = (index / (metrics.length - 1)) * width;
const y = height - (metric.metrics.total_memory_usage_mb / maxMemory) * height;
if (index === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
});
ctx.stroke();
// 레이블 추가
ctx.fillStyle = '#64748b';
ctx.font = '12px Arial';
ctx.fillText('메모리 사용량 추이', 10, 20);
ctx.fillText(`현재: ${metrics[metrics.length - 1]?.metrics.total_memory_usage_mb.toFixed(0)}MB`, 10, height - 10);
}
// 헬퍼 함수들
function getStatusText(status) {
const statusMap = {
'ready': '준비완료',
'loading': '로딩중',
'error': '오류',
'unloaded': '로드안됨'
};
return statusMap[status] || status;
}
function formatUptime(seconds) {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours}시간 ${minutes}`;
}
// 제어 함수들
async function restartModels() {
if (confirm('AI 모델을 재시작하시겠습니까? 진행 중인 작업이 중단될 수 있습니다.')) {
try {
await fetch('/api/restart-models', { method: 'POST' });
alert('모델 재시작을 시작했습니다. 잠시 후 상태가 업데이트됩니다.');
} catch (error) {
alert('모델 재시작 실패: ' + error.message);
}
}
}
async function clearCache() {
if (confirm('시스템 캐시를 정리하시겠습니까?')) {
try {
await fetch('/api/clear-cache', { method: 'POST' });
alert('캐시 정리가 완료되었습니다.');
} catch (error) {
alert('캐시 정리 실패: ' + error.message);
}
}
}
</script>
</body>
</html>