소스 수정
This commit is contained in:
@@ -4,10 +4,10 @@ export default defineEventHandler(async (event) => {
|
|||||||
const DEVIATION_THRESHOLD = 2.0
|
const DEVIATION_THRESHOLD = 2.0
|
||||||
|
|
||||||
const servers = await query<any>(`
|
const servers = await query<any>(`
|
||||||
SELECT target_id, name as server_name
|
SELECT target_id, server_name
|
||||||
FROM server_targets
|
FROM server_targets
|
||||||
WHERE is_active = 1
|
WHERE is_active = 1
|
||||||
ORDER BY name
|
ORDER BY server_name
|
||||||
`)
|
`)
|
||||||
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
@@ -22,25 +22,25 @@ export default defineEventHandler(async (event) => {
|
|||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
// 최근 14일 동일 시간대 데이터
|
// 최근 14일 동일 시간대 데이터
|
||||||
const historicalData = await query<any>(`
|
const historicalData = await query<any>(`
|
||||||
SELECT cpu_usage as cpu_percent, memory_usage as memory_percent, checked_at as collected_at
|
SELECT cpu_percent, memory_percent, collected_at
|
||||||
FROM server_logs
|
FROM server_snapshots
|
||||||
WHERE target_id = $1
|
WHERE target_id = $1
|
||||||
AND checked_at >= NOW() - INTERVAL '14 days'
|
AND collected_at::timestamp >= NOW() - INTERVAL '14 days'
|
||||||
AND EXTRACT(HOUR FROM checked_at) = $2
|
AND EXTRACT(HOUR FROM collected_at::timestamp) = $2
|
||||||
AND (
|
AND (
|
||||||
($3 = 'weekend' AND EXTRACT(DOW FROM checked_at) IN (0, 6))
|
($3 = 'weekend' AND EXTRACT(DOW FROM collected_at::timestamp) IN (0, 6))
|
||||||
OR
|
OR
|
||||||
($3 = 'weekday' AND EXTRACT(DOW FROM checked_at) NOT IN (0, 6))
|
($3 = 'weekday' AND EXTRACT(DOW FROM collected_at::timestamp) NOT IN (0, 6))
|
||||||
)
|
)
|
||||||
ORDER BY checked_at DESC
|
ORDER BY collected_at DESC
|
||||||
`, [server.target_id, currentHour, dayType])
|
`, [server.target_id, currentHour, dayType])
|
||||||
|
|
||||||
// 현재 값
|
// 현재 값
|
||||||
const currentRows = await query<any>(`
|
const currentRows = await query<any>(`
|
||||||
SELECT cpu_usage as cpu_percent, memory_usage as memory_percent
|
SELECT cpu_percent, memory_percent
|
||||||
FROM server_logs
|
FROM server_snapshots
|
||||||
WHERE target_id = $1
|
WHERE target_id = $1
|
||||||
ORDER BY checked_at DESC
|
ORDER BY collected_at DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`, [server.target_id])
|
`, [server.target_id])
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
// 활성 서버 목록
|
// 활성 서버 목록
|
||||||
const servers = await query<any>(`
|
const servers = await query<any>(`
|
||||||
SELECT target_id, name as server_name
|
SELECT target_id, server_name
|
||||||
FROM server_targets
|
FROM server_targets
|
||||||
WHERE is_active = 1
|
WHERE is_active = 1
|
||||||
ORDER BY name
|
ORDER BY server_name
|
||||||
`)
|
`)
|
||||||
|
|
||||||
const anomalies: any[] = []
|
const anomalies: any[] = []
|
||||||
@@ -16,10 +16,10 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const snapshots = await query<any>(`
|
const snapshots = await query<any>(`
|
||||||
SELECT cpu_usage as cpu_percent, memory_usage as memory_percent, checked_at as collected_at
|
SELECT cpu_percent, memory_percent, collected_at
|
||||||
FROM server_logs
|
FROM server_snapshots
|
||||||
WHERE target_id = $1
|
WHERE target_id = $1
|
||||||
ORDER BY checked_at DESC
|
ORDER BY collected_at DESC
|
||||||
LIMIT 20
|
LIMIT 20
|
||||||
`, [server.target_id])
|
`, [server.target_id])
|
||||||
|
|
||||||
|
|||||||
@@ -175,10 +175,10 @@ async function getServerDashboard() {
|
|||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
// 최신 로그
|
// 최신 로그
|
||||||
const snapshot = await queryOne(`
|
const snapshot = await queryOne(`
|
||||||
SELECT cpu_usage as cpu_percent, memory_usage as memory_percent, disk_usage as disk_percent, checked_at as collected_at
|
SELECT cpu_percent, memory_percent, collected_at
|
||||||
FROM server_logs
|
FROM server_snapshots
|
||||||
WHERE target_id = $1 AND is_success = 1
|
WHERE target_id = $1 AND is_online = 1
|
||||||
ORDER BY checked_at DESC
|
ORDER BY collected_at DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`, [server.target_id])
|
`, [server.target_id])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user