Docker 파일
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { query } 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'
|
||||
export default defineEventHandler(async (event) => {
|
||||
const queryParams = getQuery(event)
|
||||
const targetId = queryParams.target_id as string
|
||||
const period = (queryParams.period as string) || '1h'
|
||||
|
||||
if (!targetId) {
|
||||
throw createError({
|
||||
@@ -13,38 +13,41 @@ export default defineEventHandler((event) => {
|
||||
}
|
||||
|
||||
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'
|
||||
'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 interval = periodMap[period] || '1 hour'
|
||||
|
||||
const db = getDb()
|
||||
|
||||
const disks = db.prepare(`
|
||||
SELECT
|
||||
disk_id,
|
||||
device_name,
|
||||
mount_point,
|
||||
fs_type,
|
||||
disk_total,
|
||||
disk_used,
|
||||
disk_percent,
|
||||
collected_at
|
||||
FROM server_disks
|
||||
WHERE target_id = ?
|
||||
AND collected_at >= datetime('now', 'localtime', ?)
|
||||
ORDER BY collected_at ASC, mount_point ASC
|
||||
`).all(targetId, timeOffset)
|
||||
let disks: any[] = []
|
||||
try {
|
||||
disks = await query(`
|
||||
SELECT
|
||||
disk_id,
|
||||
device_name,
|
||||
mount_point,
|
||||
fs_type,
|
||||
disk_total,
|
||||
disk_used,
|
||||
disk_percent,
|
||||
collected_at
|
||||
FROM server_disks
|
||||
WHERE target_id = $1
|
||||
AND collected_at >= NOW() - INTERVAL '${interval}'
|
||||
ORDER BY collected_at ASC, mount_point ASC
|
||||
`, [targetId])
|
||||
} catch (e) {
|
||||
disks = []
|
||||
}
|
||||
|
||||
return {
|
||||
target_id: targetId,
|
||||
|
||||
Reference in New Issue
Block a user