'use client'; import type { MetricInstance } from '@/types/metrics'; import { formatTimestamp, formatPercent } from '@/lib/formatters'; interface AlertPanelProps { instances: MetricInstance[]; type: 'cpu' | 'memory' | 'disk' | 'nas'; height?: number; onZoomRange?: (startMs: number, endMs: number) => void; } interface Alert { level: 'warning' | 'critical'; category: 'threshold' | 'peak'; instance: string; message: string; startMs?: number; endMs?: number; } function generateAlerts(instances: MetricInstance[], type: string): Alert[] { const alerts: Alert[] = []; instances.forEach((inst) => { if (type === 'cpu') { if (inst.stats.max > 90) { alerts.push({ level: 'critical', category: 'threshold', instance: inst.instance, message: `최대 ${formatPercent(inst.stats.max)} 도달`, }); } } else if (type === 'memory') { if (inst.stats.max > 80) { alerts.push({ level: inst.stats.max > 90 ? 'critical' : 'warning', category: 'threshold', instance: inst.instance, message: `최대 ${formatPercent(inst.stats.max)} 도달`, }); } } else if (type === 'disk' || type === 'nas') { if (inst.stats.max > 80) { alerts.push({ level: inst.stats.max > 90 ? 'critical' : 'warning', category: 'threshold', instance: inst.instance, message: `사용률 ${formatPercent(inst.stats.max)} (증설 검토 필요)`, }); } } // Z-score peak alerts for all types inst.peaks.peaks.forEach((peak) => { alerts.push({ level: 'warning', category: 'peak', instance: inst.instance, message: `${formatTimestamp(peak.startTime)} ~ ${formatTimestamp(peak.endTime)} Peak (max: ${formatPercent(peak.maxValue)})`, startMs: peak.startTime * 1000, endMs: peak.endTime * 1000, }); }); }); return alerts; } export default function AlertPanel({ instances, type, height = 300, onZoomRange }: AlertPanelProps) { const alerts = generateAlerts(instances, type); if (alerts.length === 0) { return (

특이사항 없음

); } return (

주의 구간 ({alerts.length}건)

); }