업데이트
This commit is contained in:
@@ -92,7 +92,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'short-term' AND metric = 'CPU'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'short-term' AND metric = 'Memory'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
SELECT cpu_percent, memory_percent
|
SELECT cpu_percent, memory_percent
|
||||||
FROM server_snapshots
|
FROM server_snapshots
|
||||||
WHERE target_id = $1 AND is_online = 1
|
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
|
ORDER BY collected_at DESC
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'zscore' AND metric = 'CPU'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'zscore' AND metric = 'Memory'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -219,12 +219,12 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
SELECT cpu_percent, memory_percent
|
SELECT cpu_percent, memory_percent
|
||||||
FROM server_snapshots
|
FROM server_snapshots
|
||||||
WHERE target_id = $1 AND is_online = 1
|
WHERE target_id = $1 AND is_online = 1
|
||||||
AND collected_at >= NOW() - INTERVAL '14 days'
|
AND collected_at::timestamp >= NOW() - INTERVAL '14 days'
|
||||||
AND EXTRACT(HOUR FROM collected_at) = $2
|
AND EXTRACT(HOUR FROM collected_at::timestamp) = $2
|
||||||
AND (
|
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
|
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])
|
`, [targetId, currentHour, dayType])
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'baseline' AND metric = 'CPU'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'baseline' AND metric = 'Memory'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
SELECT cpu_percent, memory_percent
|
SELECT cpu_percent, memory_percent
|
||||||
FROM server_snapshots
|
FROM server_snapshots
|
||||||
WHERE target_id = $1 AND is_online = 1
|
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
|
ORDER BY collected_at ASC
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -341,7 +341,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'trend' AND metric = 'CPU'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
@@ -361,7 +361,7 @@ async function detectAnomalies(targetId: number, serverName: string) {
|
|||||||
const recentExists = await queryOne(`
|
const recentExists = await queryOne(`
|
||||||
SELECT 1 FROM anomaly_logs
|
SELECT 1 FROM anomaly_logs
|
||||||
WHERE target_id = $1 AND detect_type = 'trend' AND metric = 'Memory'
|
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
|
LIMIT 1
|
||||||
`, [targetId])
|
`, [targetId])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user