From 3e22cc0afcbe2b7643db61e1bc0862216eadfe97 Mon Sep 17 00:00:00 2001 From: Hyoseong Jo Date: Sun, 28 Dec 2025 15:23:51 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils/server-scheduler.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/utils/server-scheduler.ts b/backend/utils/server-scheduler.ts index bf64575..b1e026d 100644 --- a/backend/utils/server-scheduler.ts +++ b/backend/utils/server-scheduler.ts @@ -92,7 +92,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'short-term' AND metric = 'CPU' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId]) @@ -114,7 +114,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'short-term' AND metric = 'Memory' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId]) @@ -140,7 +140,7 @@ async function detectAnomalies(targetId: number, serverName: string) { SELECT cpu_percent, memory_percent FROM server_snapshots WHERE target_id = $1 AND is_online = 1 - AND collected_at >= NOW() - INTERVAL '1 hour' + AND collected_at::timestamp >= NOW() - INTERVAL '1 hour' ORDER BY collected_at DESC `, [targetId]) @@ -168,7 +168,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'zscore' AND metric = 'CPU' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId]) @@ -190,7 +190,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'zscore' AND metric = 'Memory' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId]) @@ -219,12 +219,12 @@ async function detectAnomalies(targetId: number, serverName: string) { SELECT cpu_percent, memory_percent FROM server_snapshots WHERE target_id = $1 AND is_online = 1 - AND collected_at >= NOW() - INTERVAL '14 days' - AND EXTRACT(HOUR FROM collected_at) = $2 + AND collected_at::timestamp >= NOW() - INTERVAL '14 days' + AND EXTRACT(HOUR FROM collected_at::timestamp) = $2 AND ( - ($3 = 'weekend' AND EXTRACT(DOW FROM collected_at) IN (0, 6)) + ($3 = 'weekend' AND EXTRACT(DOW FROM collected_at::timestamp) IN (0, 6)) OR - ($3 = 'weekday' AND EXTRACT(DOW FROM collected_at) NOT IN (0, 6)) + ($3 = 'weekday' AND EXTRACT(DOW FROM collected_at::timestamp) NOT IN (0, 6)) ) `, [targetId, currentHour, dayType]) @@ -257,7 +257,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'baseline' AND metric = 'CPU' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId]) @@ -279,7 +279,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'baseline' AND metric = 'Memory' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId]) @@ -306,7 +306,7 @@ async function detectAnomalies(targetId: number, serverName: string) { SELECT cpu_percent, memory_percent FROM server_snapshots WHERE target_id = $1 AND is_online = 1 - AND collected_at >= NOW() - INTERVAL '${WINDOW_MINUTES} minutes' + AND collected_at::timestamp >= NOW() - INTERVAL '${WINDOW_MINUTES} minutes' ORDER BY collected_at ASC `, [targetId]) @@ -341,7 +341,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'trend' AND metric = 'CPU' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId]) @@ -361,7 +361,7 @@ async function detectAnomalies(targetId: number, serverName: string) { const recentExists = await queryOne(` SELECT 1 FROM anomaly_logs WHERE target_id = $1 AND detect_type = 'trend' AND metric = 'Memory' - AND detected_at > NOW() - INTERVAL '1 minute' + AND detected_at::timestamp > NOW() - INTERVAL '1 minute' LIMIT 1 `, [targetId])