시스템 모니터
This commit is contained in:
38
backend/api/anomaly/logs.get.ts
Normal file
38
backend/api/anomaly/logs.get.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { getDb } from '../../utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const db = getDb()
|
||||
const query = getQuery(event)
|
||||
|
||||
const type = query.type as string || 'short-term'
|
||||
const period = query.period as string || '24h'
|
||||
|
||||
// 기간 계산
|
||||
let intervalClause = ''
|
||||
if (period.endsWith('h')) {
|
||||
const hours = parseInt(period)
|
||||
intervalClause = `'-${hours} hours'`
|
||||
} else if (period.endsWith('d')) {
|
||||
const days = parseInt(period)
|
||||
intervalClause = `'-${days} days'`
|
||||
} else {
|
||||
intervalClause = `'-24 hours'`
|
||||
}
|
||||
|
||||
const logs = db.prepare(`
|
||||
SELECT id, target_id, server_name, detect_type, metric, level,
|
||||
current_value, threshold_value, message, detected_at
|
||||
FROM anomaly_logs
|
||||
WHERE detect_type = ?
|
||||
AND detected_at >= datetime('now', ${intervalClause}, 'localtime')
|
||||
ORDER BY detected_at DESC
|
||||
LIMIT 100
|
||||
`).all(type) as any[]
|
||||
|
||||
return {
|
||||
logs,
|
||||
type,
|
||||
period,
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user