소스 수정
This commit is contained in:
28
backend/api/server/location-stats.get.ts
Normal file
28
backend/api/server/location-stats.get.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { query } from '../../utils/db'
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const stats = await query(`
|
||||
SELECT
|
||||
t.physical_location,
|
||||
COUNT(DISTINCT t.target_id) as server_count,
|
||||
ROUND(AVG(s.cpu_temp)::numeric, 1) as avg_temp,
|
||||
ROUND(SUM(n.speed_recv)::numeric, 0) as total_rx,
|
||||
ROUND(SUM(n.speed_sent)::numeric, 0) as total_tx
|
||||
FROM server_targets t
|
||||
LEFT JOIN server_snapshots s ON t.target_id = s.target_id
|
||||
AND s.collected_at::timestamp >= NOW() - INTERVAL '10 minutes'
|
||||
LEFT JOIN server_networks n ON t.target_id = n.target_id
|
||||
AND n.collected_at::timestamp >= NOW() - INTERVAL '10 minutes'
|
||||
WHERE t.is_active = 1
|
||||
GROUP BY t.physical_location
|
||||
ORDER BY t.physical_location
|
||||
`)
|
||||
|
||||
return stats.map((row: any) => ({
|
||||
location: row.physical_location || '미지정',
|
||||
serverCount: Number(row.server_count) || 0,
|
||||
avgTemp: row.avg_temp ? parseFloat(row.avg_temp) : null,
|
||||
totalRx: Number(row.total_rx) || 0,
|
||||
totalTx: Number(row.total_tx) || 0
|
||||
}))
|
||||
})
|
||||
@@ -183,6 +183,17 @@ async function getServerDashboard() {
|
||||
LIMIT 1
|
||||
`, [server.target_id])
|
||||
|
||||
// 최신 디스크 사용률 (최대값)
|
||||
const diskData = await queryOne(`
|
||||
SELECT MAX(disk_percent) as 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')
|
||||
`, [server.target_id])
|
||||
|
||||
// 오프라인 체크
|
||||
let isOffline = true
|
||||
let lastCollected = null
|
||||
@@ -199,7 +210,7 @@ async function getServerDashboard() {
|
||||
if (!isOffline && snapshot) {
|
||||
cpuLevel = getLevel(Number(snapshot.cpu_percent), thresholds.server?.cpu || { warning: 70, critical: 85, danger: 95 })
|
||||
memLevel = getLevel(Number(snapshot.memory_percent), thresholds.server?.memory || { warning: 80, critical: 90, danger: 95 })
|
||||
diskLevel = getLevel(Number(snapshot.disk_percent), thresholds.server?.disk || { warning: 80, critical: 90, danger: 95 })
|
||||
diskLevel = getLevel(Number(diskData?.disk_percent), thresholds.server?.disk || { warning: 80, critical: 90, danger: 95 })
|
||||
serverLevel = getHighestLevel([cpuLevel, memLevel, diskLevel])
|
||||
}
|
||||
|
||||
@@ -280,7 +291,7 @@ async function getServerDashboard() {
|
||||
cpu_level: cpuLevel,
|
||||
memory_percent: snapshot?.memory_percent ?? null,
|
||||
memory_level: memLevel,
|
||||
disk_percent: snapshot?.disk_percent ?? null,
|
||||
disk_percent: diskData?.disk_percent ?? null,
|
||||
disk_level: diskLevel,
|
||||
last_collected: lastCollected,
|
||||
containers: containers,
|
||||
|
||||
Reference in New Issue
Block a user