Docker 파일

This commit is contained in:
2025-12-28 14:31:12 +09:00
parent ba7a208da9
commit 6196c03e46
23 changed files with 302 additions and 355 deletions

View File

@@ -1,8 +1,8 @@
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
export default defineEventHandler(async (event) => {
const queryParams = getQuery(event)
const targetId = queryParams.target_id as string
if (!targetId) {
throw createError({
@@ -11,20 +11,22 @@ export default defineEventHandler((event) => {
})
}
const db = getDb()
// 최신 수집 시간 기준 컨테이너 목록
const containers = db.prepare(`
SELECT DISTINCT container_name
FROM server_containers
WHERE target_id = ?
AND collected_at = (
SELECT MAX(collected_at)
FROM server_containers
WHERE target_id = ?
)
ORDER BY container_name ASC
`).all(targetId, targetId)
let containers: any[] = []
try {
containers = await query(`
SELECT DISTINCT container_name
FROM server_containers
WHERE target_id = $1
AND collected_at = (
SELECT MAX(collected_at)
FROM server_containers
WHERE target_id = $1
)
ORDER BY container_name ASC
`, [targetId])
} catch (e) {
containers = []
}
return containers.map((c: any) => c.container_name)
})

View File

@@ -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,41 +13,44 @@ 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 containers = db.prepare(`
SELECT
container_id,
container_name,
container_status,
cpu_percent,
memory_usage,
memory_limit,
memory_percent,
uptime,
network_rx,
network_tx,
collected_at
FROM server_containers
WHERE target_id = ?
AND collected_at >= datetime('now', 'localtime', ?)
ORDER BY collected_at ASC, container_name ASC
`).all(targetId, timeOffset)
let containers: any[] = []
try {
containers = await query(`
SELECT
container_id,
container_name,
container_status,
cpu_percent,
memory_usage,
memory_limit,
memory_percent,
uptime,
network_rx,
network_tx,
collected_at
FROM server_containers
WHERE target_id = $1
AND collected_at >= NOW() - INTERVAL '${interval}'
ORDER BY collected_at ASC, container_name ASC
`, [targetId])
} catch (e) {
containers = []
}
return {
target_id: targetId,

View File

@@ -1,8 +1,8 @@
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
export default defineEventHandler(async (event) => {
const queryParams = getQuery(event)
const targetId = queryParams.target_id as string
if (!targetId) {
throw createError({
@@ -11,19 +11,21 @@ export default defineEventHandler((event) => {
})
}
const db = getDb()
// 최신 수집 시간 기준 디스크 목록 (물리 디스크만)
const disks = db.prepare(`
SELECT DISTINCT device_name, mount_point, fs_type, disk_total, disk_used, disk_percent
FROM server_disks
WHERE target_id = ?
AND collected_at = (SELECT MAX(collected_at) FROM server_disks WHERE target_id = ?)
AND device_name NOT LIKE '%loop%'
AND mount_point NOT LIKE '%/snap%'
AND fs_type NOT IN ('tmpfs', 'squashfs', 'overlay')
ORDER BY mount_point ASC
`).all(targetId, targetId)
let disks: any[] = []
try {
disks = await query(`
SELECT DISTINCT device_name, mount_point, fs_type, disk_total, disk_used, disk_percent
FROM server_disks
WHERE target_id = $1
AND collected_at = (SELECT MAX(collected_at) FROM server_disks WHERE target_id = $1)
AND device_name NOT LIKE '%loop%'
AND mount_point NOT LIKE '%/snap%'
AND fs_type NOT IN ('tmpfs', 'squashfs', 'overlay')
ORDER BY mount_point ASC
`, [targetId])
} catch (e) {
disks = []
}
return disks
})

View File

@@ -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,

View File

@@ -1,8 +1,8 @@
import { getDb } from '../../../utils/db'
import { queryOne } from '../../../utils/db'
export default defineEventHandler((event) => {
const query = getQuery(event)
const targetId = query.target_id as string
export default defineEventHandler(async (event) => {
const queryParams = getQuery(event)
const targetId = queryParams.target_id as string
if (!targetId) {
throw createError({
@@ -11,22 +11,17 @@ export default defineEventHandler((event) => {
})
}
const db = getDb()
// 최신 스냅샷
const snapshot = db.prepare(`
const snapshot = await queryOne(`
SELECT
s.*,
t.server_name,
t.server_ip,
t.glances_url,
t.collect_interval
FROM server_snapshots s
JOIN server_targets t ON s.target_id = t.target_id
WHERE s.target_id = ?
ORDER BY s.collected_at DESC
l.*,
t.name as server_name,
t.host as server_ip
FROM server_logs l
JOIN server_targets t ON l.target_id = t.target_id
WHERE l.target_id = $1
ORDER BY l.checked_at DESC
LIMIT 1
`).get(targetId)
`, [targetId])
return snapshot || null
})

View File

@@ -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 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)
let networks: any[] = []
try {
networks = await query(`
SELECT
network_id,
interface_name,
bytes_recv,
bytes_sent,
speed_recv,
speed_sent,
is_up,
collected_at
FROM server_networks
WHERE target_id = $1
AND collected_at >= NOW() - INTERVAL '${interval}'
ORDER BY collected_at ASC, interface_name ASC
`, [targetId])
} catch (e) {
networks = []
}
return {
target_id: targetId,

View File

@@ -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({
@@ -12,44 +12,35 @@ 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 snapshots = db.prepare(`
const snapshots = await query(`
SELECT
snapshot_id,
cpu_percent,
cpu_temp,
load_percent,
memory_percent,
memory_used,
memory_total,
swap_percent,
swap_used,
swap_total,
is_online,
collected_at
FROM server_snapshots
WHERE target_id = ?
AND collected_at >= datetime('now', 'localtime', ?)
ORDER BY collected_at ASC
`).all(targetId, timeOffset)
log_id,
cpu_usage as cpu_percent,
memory_usage as memory_percent,
disk_usage as disk_percent,
is_success as is_online,
checked_at as collected_at
FROM server_logs
WHERE target_id = $1
AND checked_at >= NOW() - INTERVAL '${interval}'
ORDER BY checked_at ASC
`, [targetId])
return {
target_id: targetId,