시스템 모니터

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,54 @@
import { getDb } from '../../../utils/db'
export default defineEventHandler((event) => {
const query = getQuery(event)
const targetId = query.target_id as string
const period = (query.period as string) || '1h'
if (!targetId) {
throw createError({
statusCode: 400,
message: 'target_id is required'
})
}
const periodMap: Record<string, string> = {
'1h': '-1 hour',
'2h': '-2 hours',
'3h': '-3 hours',
'4h': '-4 hours',
'5h': '-5 hours',
'6h': '-6 hours',
'12h': '-12 hours',
'18h': '-18 hours',
'24h': '-24 hours',
'7d': '-7 days',
'30d': '-30 days'
}
const timeOffset = periodMap[period] || '-1 hour'
const db = getDb()
const networks = db.prepare(`
SELECT
network_id,
interface_name,
bytes_recv,
bytes_sent,
speed_recv,
speed_sent,
is_up,
collected_at
FROM server_networks
WHERE target_id = ?
AND collected_at >= datetime('now', 'localtime', ?)
ORDER BY collected_at ASC, interface_name ASC
`).all(targetId, timeOffset)
return {
target_id: targetId,
period,
data: networks
}
})