소스 수정
This commit is contained in:
@@ -87,8 +87,8 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
const cpuChange = prevCpuAvg > 1 ? ((currCpuAvg - prevCpuAvg) / prevCpuAvg) * 100 : currCpuAvg - prevCpuAvg
|
||||
const memChange = prevMemAvg > 1 ? ((currMemAvg - prevMemAvg) / prevMemAvg) * 100 : currMemAvg - prevMemAvg
|
||||
|
||||
// CPU 단기 변화율 체크
|
||||
if (Math.abs(cpuChange) >= SHORT_TERM_THRESHOLD) {
|
||||
// CPU 단기 변화율 체크 (증가만 감지)
|
||||
if (cpuChange >= SHORT_TERM_THRESHOLD) {
|
||||
const recentExists = await queryOne(`
|
||||
SELECT 1 FROM anomaly_logs
|
||||
WHERE target_id = $1 AND detect_type = 'short-term' AND metric = 'CPU'
|
||||
@@ -97,20 +97,19 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
`, [targetId])
|
||||
|
||||
if (!recentExists) {
|
||||
const level = Math.abs(cpuChange) >= 100 ? 'danger' : 'warning'
|
||||
const direction = cpuChange >= 0 ? '증가' : '감소'
|
||||
const message = `CPU ${direction} 감지 (${prevCpuAvg.toFixed(1)}% → ${currCpuAvg.toFixed(1)}%)`
|
||||
const level = cpuChange >= 100 ? 'danger' : 'warning'
|
||||
const message = `CPU 급증 감지 (${prevCpuAvg.toFixed(1)}% → ${currCpuAvg.toFixed(1)}%)`
|
||||
|
||||
await execute(`
|
||||
INSERT INTO anomaly_logs (target_id, server_name, detect_type, metric, level, current_value, threshold_value, message)
|
||||
VALUES ($1, $2, 'short-term', 'CPU', $3, $4, $5, $6)
|
||||
`, [targetId, serverName, level, currCpuAvg, cpuChange, message])
|
||||
console.log(`[${now}] 🚨 [${serverName}] 단기변화율 이상감지: CPU ${cpuChange.toFixed(1)}% (${level})`)
|
||||
console.log(`[${now}] 🚨 [${serverName}] 단기변화율 이상감지: CPU +${cpuChange.toFixed(1)}% (${level})`)
|
||||
}
|
||||
}
|
||||
|
||||
// Memory 단기 변화율 체크
|
||||
if (Math.abs(memChange) >= SHORT_TERM_THRESHOLD) {
|
||||
// Memory 단기 변화율 체크 (증가만 감지)
|
||||
if (memChange >= SHORT_TERM_THRESHOLD) {
|
||||
const recentExists = await queryOne(`
|
||||
SELECT 1 FROM anomaly_logs
|
||||
WHERE target_id = $1 AND detect_type = 'short-term' AND metric = 'Memory'
|
||||
@@ -119,15 +118,14 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
`, [targetId])
|
||||
|
||||
if (!recentExists) {
|
||||
const level = Math.abs(memChange) >= 100 ? 'danger' : 'warning'
|
||||
const direction = memChange >= 0 ? '증가' : '감소'
|
||||
const message = `Memory ${direction} 감지 (${prevMemAvg.toFixed(1)}% → ${currMemAvg.toFixed(1)}%)`
|
||||
const level = memChange >= 100 ? 'danger' : 'warning'
|
||||
const message = `Memory 급증 감지 (${prevMemAvg.toFixed(1)}% → ${currMemAvg.toFixed(1)}%)`
|
||||
|
||||
await execute(`
|
||||
INSERT INTO anomaly_logs (target_id, server_name, detect_type, metric, level, current_value, threshold_value, message)
|
||||
VALUES ($1, $2, 'short-term', 'Memory', $3, $4, $5, $6)
|
||||
`, [targetId, serverName, level, currMemAvg, memChange, message])
|
||||
console.log(`[${now}] 🚨 [${serverName}] 단기변화율 이상감지: Memory ${memChange.toFixed(1)}% (${level})`)
|
||||
console.log(`[${now}] 🚨 [${serverName}] 단기변화율 이상감지: Memory +${memChange.toFixed(1)}% (${level})`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,8 +161,8 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
const cpuZscore = cpuStd > 0.1 ? (currCpu - cpuAvg) / cpuStd : 0
|
||||
const memZscore = memStd > 0.1 ? (currMem - memAvg) / memStd : 0
|
||||
|
||||
// CPU Z-Score 체크
|
||||
if (Math.abs(cpuZscore) >= WARNING_Z) {
|
||||
// CPU Z-Score 체크 (높은 경우만 감지)
|
||||
if (cpuZscore >= WARNING_Z) {
|
||||
const recentExists = await queryOne(`
|
||||
SELECT 1 FROM anomaly_logs
|
||||
WHERE target_id = $1 AND detect_type = 'zscore' AND metric = 'CPU'
|
||||
@@ -173,9 +171,8 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
`, [targetId])
|
||||
|
||||
if (!recentExists) {
|
||||
const level = Math.abs(cpuZscore) >= DANGER_Z ? 'danger' : 'warning'
|
||||
const direction = cpuZscore >= 0 ? '높음' : '낮음'
|
||||
const message = `CPU 평균 대비 ${Math.abs(cpuZscore).toFixed(1)}σ ${direction} (평균: ${cpuAvg.toFixed(1)}%, 현재: ${currCpu.toFixed(1)}%)`
|
||||
const level = cpuZscore >= DANGER_Z ? 'danger' : 'warning'
|
||||
const message = `CPU 평균 대비 ${cpuZscore.toFixed(1)}σ 높음 (평균: ${cpuAvg.toFixed(1)}%, 현재: ${currCpu.toFixed(1)}%)`
|
||||
|
||||
await execute(`
|
||||
INSERT INTO anomaly_logs (target_id, server_name, detect_type, metric, level, current_value, threshold_value, message)
|
||||
@@ -185,8 +182,8 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Memory Z-Score 체크
|
||||
if (Math.abs(memZscore) >= WARNING_Z) {
|
||||
// Memory Z-Score 체크 (높은 경우만 감지)
|
||||
if (memZscore >= WARNING_Z) {
|
||||
const recentExists = await queryOne(`
|
||||
SELECT 1 FROM anomaly_logs
|
||||
WHERE target_id = $1 AND detect_type = 'zscore' AND metric = 'Memory'
|
||||
@@ -195,9 +192,8 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
`, [targetId])
|
||||
|
||||
if (!recentExists) {
|
||||
const level = Math.abs(memZscore) >= DANGER_Z ? 'danger' : 'warning'
|
||||
const direction = memZscore >= 0 ? '높음' : '낮음'
|
||||
const message = `Memory 평균 대비 ${Math.abs(memZscore).toFixed(1)}σ ${direction} (평균: ${memAvg.toFixed(1)}%, 현재: ${currMem.toFixed(1)}%)`
|
||||
const level = memZscore >= DANGER_Z ? 'danger' : 'warning'
|
||||
const message = `Memory 평균 대비 ${memZscore.toFixed(1)}σ 높음 (평균: ${memAvg.toFixed(1)}%, 현재: ${currMem.toFixed(1)}%)`
|
||||
|
||||
await execute(`
|
||||
INSERT INTO anomaly_logs (target_id, server_name, detect_type, metric, level, current_value, threshold_value, message)
|
||||
@@ -253,7 +249,8 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
const cpuDeviation = cpuStd > 0.1 ? (currCpu - cpuAvg) / cpuStd : 0
|
||||
const memDeviation = memStd > 0.1 ? (currMem - memAvg) / memStd : 0
|
||||
|
||||
if (Math.abs(cpuDeviation) >= DEVIATION_THRESHOLD) {
|
||||
// CPU 베이스라인 체크 (높은 경우만 감지)
|
||||
if (cpuDeviation >= DEVIATION_THRESHOLD) {
|
||||
const recentExists = await queryOne(`
|
||||
SELECT 1 FROM anomaly_logs
|
||||
WHERE target_id = $1 AND detect_type = 'baseline' AND metric = 'CPU'
|
||||
@@ -262,10 +259,9 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
`, [targetId])
|
||||
|
||||
if (!recentExists) {
|
||||
const level = Math.abs(cpuDeviation) >= 3.0 ? 'danger' : 'warning'
|
||||
const direction = cpuDeviation >= 0 ? '높음' : '낮음'
|
||||
const level = cpuDeviation >= 3.0 ? 'danger' : 'warning'
|
||||
const dayLabel = isWeekend ? '주말' : '평일'
|
||||
const message = `CPU ${dayLabel} ${currentHour}시 베이스라인 대비 ${Math.abs(cpuDeviation).toFixed(1)}σ ${direction}`
|
||||
const message = `CPU ${dayLabel} ${currentHour}시 베이스라인 대비 ${cpuDeviation.toFixed(1)}σ 높음`
|
||||
|
||||
await execute(`
|
||||
INSERT INTO anomaly_logs (target_id, server_name, detect_type, metric, level, current_value, threshold_value, message)
|
||||
@@ -275,7 +271,8 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.abs(memDeviation) >= DEVIATION_THRESHOLD) {
|
||||
// Memory 베이스라인 체크 (높은 경우만 감지)
|
||||
if (memDeviation >= DEVIATION_THRESHOLD) {
|
||||
const recentExists = await queryOne(`
|
||||
SELECT 1 FROM anomaly_logs
|
||||
WHERE target_id = $1 AND detect_type = 'baseline' AND metric = 'Memory'
|
||||
@@ -284,10 +281,9 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
||||
`, [targetId])
|
||||
|
||||
if (!recentExists) {
|
||||
const level = Math.abs(memDeviation) >= 3.0 ? 'danger' : 'warning'
|
||||
const direction = memDeviation >= 0 ? '높음' : '낮음'
|
||||
const level = memDeviation >= 3.0 ? 'danger' : 'warning'
|
||||
const dayLabel = isWeekend ? '주말' : '평일'
|
||||
const message = `Memory ${dayLabel} ${currentHour}시 베이스라인 대비 ${Math.abs(memDeviation).toFixed(1)}σ ${direction}`
|
||||
const message = `Memory ${dayLabel} ${currentHour}시 베이스라인 대비 ${memDeviation.toFixed(1)}σ 높음`
|
||||
|
||||
await execute(`
|
||||
INSERT INTO anomaly_logs (target_id, server_name, detect_type, metric, level, current_value, threshold_value, message)
|
||||
|
||||
Reference in New Issue
Block a user