시스템 모니터

This commit is contained in:
2025-12-28 12:03:48 +09:00
parent dbae6649bc
commit a871ec8008
73 changed files with 21354 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
import { getDb } from '../../utils/db'
export default defineEventHandler(() => {
const db = getDb()
const rows = db.prepare(`
SELECT category, metric, warning, critical, danger, updated_at
FROM thresholds
ORDER BY category, metric
`).all() as any[]
// 카테고리별로 그룹화
const result: Record<string, Record<string, { warning: number; critical: number; danger: number }>> = {}
for (const row of rows) {
if (!result[row.category]) {
result[row.category] = {}
}
result[row.category][row.metric] = {
warning: row.warning,
critical: row.critical,
danger: row.danger
}
}
return result
})

View File

@@ -0,0 +1,54 @@
import { getDb } from '../../utils/db'
export default defineEventHandler(async (event) => {
const body = await readBody(event)
if (!body || typeof body !== 'object') {
throw createError({
statusCode: 400,
message: 'Invalid request body'
})
}
const db = getDb()
const now = new Date().toLocaleString('sv-SE', { timeZone: 'Asia/Seoul' }).replace('T', ' ')
const stmt = db.prepare(`
UPDATE thresholds
SET warning = ?, critical = ?, danger = ?, updated_at = ?
WHERE category = ? AND metric = ?
`)
let updated = 0
for (const [category, metrics] of Object.entries(body)) {
if (typeof metrics !== 'object') continue
for (const [metric, values] of Object.entries(metrics as Record<string, any>)) {
if (!values || typeof values !== 'object') continue
const { warning, critical, danger } = values
// 유효성 검사
if (typeof warning !== 'number' || typeof critical !== 'number' || typeof danger !== 'number') {
continue
}
if (warning < 0 || warning > 100 || critical < 0 || critical > 100 || danger < 0 || danger > 100) {
continue
}
if (warning >= critical || critical >= danger) {
throw createError({
statusCode: 400,
message: `Invalid thresholds for ${category}.${metric}: warning < critical < danger 순서여야 합니다.`
})
}
const result = stmt.run(warning, critical, danger, now, category, metric)
if (result.changes > 0) updated++
}
}
return { success: true, updated }
})