소스 수정
This commit is contained in:
@@ -6,10 +6,10 @@ export default defineEventHandler(async (event) => {
|
||||
const WINDOW_MINUTES = 30
|
||||
|
||||
const servers = await query<any>(`
|
||||
SELECT target_id, name as server_name
|
||||
SELECT target_id, server_name
|
||||
FROM server_targets
|
||||
WHERE is_active = 1
|
||||
ORDER BY name
|
||||
ORDER BY server_name
|
||||
`)
|
||||
|
||||
const anomalies: any[] = []
|
||||
@@ -17,12 +17,12 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
for (const server of servers) {
|
||||
const snapshots = await query<any>(`
|
||||
SELECT cpu_usage as cpu_percent, memory_usage as memory_percent, checked_at as collected_at,
|
||||
EXTRACT(EPOCH FROM (NOW() - checked_at)) / 60 as minutes_ago
|
||||
FROM server_logs
|
||||
WHERE target_id = $1 AND is_success = 1
|
||||
AND checked_at >= NOW() - INTERVAL '${WINDOW_MINUTES} minutes'
|
||||
ORDER BY checked_at ASC
|
||||
SELECT cpu_percent, memory_percent, collected_at,
|
||||
EXTRACT(EPOCH FROM (NOW() - collected_at::timestamp)) / 60 as minutes_ago
|
||||
FROM server_snapshots
|
||||
WHERE target_id = $1 AND is_online = 1
|
||||
AND collected_at::timestamp >= NOW() - INTERVAL '${WINDOW_MINUTES} minutes'
|
||||
ORDER BY collected_at ASC
|
||||
`, [server.target_id])
|
||||
|
||||
if (snapshots.length < MIN_SAMPLES) {
|
||||
|
||||
@@ -5,10 +5,10 @@ export default defineEventHandler(async (event) => {
|
||||
const DANGER_Z = 3.0
|
||||
|
||||
const servers = await query<any>(`
|
||||
SELECT target_id, name as server_name
|
||||
SELECT target_id, server_name
|
||||
FROM server_targets
|
||||
WHERE is_active = 1
|
||||
ORDER BY name
|
||||
ORDER BY server_name
|
||||
`)
|
||||
|
||||
const anomalies: any[] = []
|
||||
@@ -16,11 +16,11 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
for (const server of servers) {
|
||||
const snapshots = await query<any>(`
|
||||
SELECT cpu_usage as cpu_percent, memory_usage as memory_percent, checked_at as collected_at
|
||||
FROM server_logs
|
||||
SELECT cpu_percent, memory_percent, collected_at
|
||||
FROM server_snapshots
|
||||
WHERE target_id = $1
|
||||
AND checked_at >= NOW() - INTERVAL '1 hour'
|
||||
ORDER BY checked_at DESC
|
||||
AND collected_at::timestamp >= NOW() - INTERVAL '1 hour'
|
||||
ORDER BY collected_at DESC
|
||||
`, [server.target_id])
|
||||
|
||||
if (snapshots.length < 10) {
|
||||
|
||||
@@ -13,13 +13,13 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const snapshot = await queryOne(`
|
||||
SELECT
|
||||
l.*,
|
||||
t.name as server_name,
|
||||
t.host as server_ip
|
||||
FROM server_logs l
|
||||
JOIN server_targets t ON l.target_id = t.target_id
|
||||
WHERE l.target_id = $1
|
||||
ORDER BY l.checked_at DESC
|
||||
s.*,
|
||||
t.server_name,
|
||||
t.server_ip
|
||||
FROM server_snapshots s
|
||||
JOIN server_targets t ON s.target_id = t.target_id
|
||||
WHERE s.target_id = $1
|
||||
ORDER BY s.collected_at DESC
|
||||
LIMIT 1
|
||||
`, [targetId])
|
||||
|
||||
|
||||
@@ -30,16 +30,15 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const snapshots = await query(`
|
||||
SELECT
|
||||
log_id,
|
||||
cpu_usage as cpu_percent,
|
||||
memory_usage as memory_percent,
|
||||
disk_usage as disk_percent,
|
||||
is_success as is_online,
|
||||
checked_at as collected_at
|
||||
FROM server_logs
|
||||
snapshot_id,
|
||||
cpu_percent,
|
||||
memory_percent,
|
||||
is_online,
|
||||
collected_at
|
||||
FROM server_snapshots
|
||||
WHERE target_id = $1
|
||||
AND checked_at >= NOW() - INTERVAL '${interval}'
|
||||
ORDER BY checked_at ASC
|
||||
AND collected_at::timestamp >= NOW() - INTERVAL '${interval}'
|
||||
ORDER BY collected_at ASC
|
||||
`, [targetId])
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user