소스 수정

This commit is contained in:
2025-12-28 17:35:46 +09:00
parent 24741e2445
commit 1aeeab4d40
6 changed files with 236 additions and 15 deletions

View File

@@ -0,0 +1,160 @@
<template>
<div class="location-stats-card">
<div class="card-header">
<span class="card-icon">🏢</span>
<span class="card-title">물리공간</span>
</div>
<div class="location-list">
<div
v-for="loc in locations"
:key="loc.location"
class="location-item"
:class="getTempClass(loc.avgTemp)"
>
<div class="loc-name">{{ loc.location }}</div>
<div class="loc-stats">
<div class="stat-row temp">
<span class="stat-icon">🌡</span>
<span class="stat-value">{{ loc.avgTemp ? loc.avgTemp + '°C' : '-' }}</span>
</div>
<div class="stat-row traffic">
<span class="stat-icon"></span>
<span class="stat-value rx">{{ formatBytes(loc.totalRx) }}</span>
</div>
<div class="stat-row traffic">
<span class="stat-icon"></span>
<span class="stat-value tx">{{ formatBytes(loc.totalTx) }}</span>
</div>
</div>
<div class="loc-servers">{{ loc.serverCount }}</div>
</div>
<div v-if="!locations || locations.length === 0" class="no-data">
데이터 없음
</div>
</div>
</div>
</template>
<script setup lang="ts">
interface LocationStat {
location: string
serverCount: number
avgTemp: number | null
totalRx: number
totalTx: number
}
defineProps<{
locations: LocationStat[]
}>()
function getTempClass(temp: number | null): string {
if (temp === null) return ''
if (temp >= 70) return 'temp-critical'
if (temp >= 60) return 'temp-warning'
return 'temp-normal'
}
function formatBytes(bytes: number): string {
if (!bytes || bytes === 0) return '0 B/s'
if (bytes >= 1024 * 1024 * 1024) return (bytes / (1024 * 1024 * 1024)).toFixed(1) + ' GB/s'
if (bytes >= 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(1) + ' MB/s'
if (bytes >= 1024) return (bytes / 1024).toFixed(1) + ' KB/s'
return bytes.toFixed(0) + ' B/s'
}
</script>
<style scoped>
.location-stats-card {
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 12px;
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
overflow: hidden;
}
.card-header {
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 10px;
padding-bottom: 8px;
border-bottom: 1px solid var(--border-color);
}
.card-icon { font-size: 18px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.location-list {
display: flex;
flex-direction: column;
gap: 8px;
overflow-y: auto;
flex: 1;
}
.location-item {
background: var(--bg-tertiary, #f8fafc);
border-radius: 8px;
padding: 10px;
border-left: 3px solid #22c55e;
}
.location-item.temp-warning { border-left-color: #f59e0b; }
.location-item.temp-critical { border-left-color: #ef4444; }
.loc-name {
font-size: 12px;
font-weight: 600;
color: var(--text-primary);
margin-bottom: 6px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.loc-stats {
display: flex;
flex-direction: column;
gap: 3px;
}
.stat-row {
display: flex;
align-items: center;
gap: 4px;
font-size: 11px;
}
.stat-icon {
width: 14px;
text-align: center;
color: var(--text-muted);
}
.stat-value {
color: var(--text-secondary);
font-family: monospace;
}
.stat-value.rx { color: #06b6d4; }
.stat-value.tx { color: #f59e0b; }
.loc-servers {
font-size: 10px;
color: var(--text-muted);
text-align: right;
margin-top: 4px;
}
.no-data {
font-size: 12px;
color: var(--text-muted);
text-align: center;
padding: 20px 0;
}
</style>

View File

@@ -56,10 +56,10 @@ function formatTimeAgo(datetime: string | null): string {
display: flex;
flex-direction: column;
align-items: center;
padding: 16px 12px;
padding: 10px 8px;
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 12px;
border-radius: 10px;
cursor: pointer;
transition: all 0.2s;
text-align: center;
@@ -73,12 +73,12 @@ function formatTimeAgo(datetime: string | null): string {
.network-card.unhealthy { border-top: 4px solid #ef4444; }
.network-card.pending { border-top: 4px solid #9ca3af; }
.card-icon { font-size: 28px; margin-bottom: 8px; }
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 10px; }
.card-icon { font-size: 22px; margin-bottom: 4px; }
.card-title { font-size: 12px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.card-status { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 4px; }
.status-icon { font-size: 16px; }
.status-text { font-size: 15px; font-weight: 500; color: var(--text-secondary); }
.card-status { display: flex; align-items: center; justify-content: center; gap: 4px; margin-bottom: 2px; }
.status-icon { font-size: 14px; }
.status-text { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.card-time { font-size: 12px; color: var(--text-muted); }
.card-time { font-size: 10px; color: var(--text-muted); }
</style>

View File

@@ -102,7 +102,7 @@
<div class="mini-bar">
<div :class="['mini-fill', getContainerMemLevel(container)]" :style="{ width: getMemPercent(container) + '%' }"></div>
</div>
<span class="value">{{ formatMemoryShort(container.memory_usage) }}</span>
<span :class="['value', { 'mem-highlight': isMemoryOver1GB(container.memory_usage) }]">{{ formatMemoryShort(container.memory_usage) }}</span>
</div>
<div class="card-metric">
<span class="label">RX</span>
@@ -211,9 +211,15 @@ function getMemPercent(c: ContainerStatus): number {
function formatMemoryShort(bytes: number | null): string {
if (bytes === null || bytes === undefined) return '-'
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)}K`
if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(0)}M`
return `${(bytes / 1024 / 1024 / 1024).toFixed(1)}G`
const numBytes = Number(bytes)
if (numBytes < 1024 * 1024) return `${(numBytes / 1024).toFixed(0)}K`
if (numBytes < 1024 * 1024 * 1024) return `${(numBytes / 1024 / 1024).toFixed(0)}M`
return `${(numBytes / 1024 / 1024 / 1024).toFixed(1)}G`
}
function isMemoryOver1GB(bytes: number | null): boolean {
if (bytes === null || bytes === undefined) return false
return Number(bytes) >= 1024 * 1024 * 1024
}
function formatNetworkShort(bytes: number | null): string {
@@ -312,6 +318,7 @@ function formatTimeAgo(datetime: string | null): string {
.mini-fill.critical { background: #f97316; }
.mini-fill.danger { background: #ef4444; }
.card-metric .value { font-size: 11px; font-weight: 500; color: var(--text-secondary); width: 36px; text-align: right; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; }
.card-metric .value.mem-highlight { color: #dc2626; font-weight: 700; }
.card-stopped { font-size: 12px; color: var(--text-muted); font-style: italic; text-align: center; padding: 6px 0; }

View File

@@ -48,6 +48,9 @@
icon="🔒"
:status="privnetStatus"
/>
<LocationStatsPortlet
:locations="locationStats"
/>
</div>
</div>
</main>
@@ -83,11 +86,21 @@ let loadingStartTime = 0
const pubnetStatus = ref<any>(null)
const privnetStatus = ref<any>(null)
const serverDashboard = ref<any>(null)
const locationStats = ref<any[]>([])
// WebSocket
let ws: WebSocket | null = null
let timeInterval: ReturnType<typeof window.setInterval> | null = null
async function fetchLocationStats() {
try {
const data = await $fetch('/api/server/location-stats')
locationStats.value = data as any[]
} catch (err) {
console.error('Failed to fetch location stats:', err)
}
}
function formatTime(date: Date): string {
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
@@ -162,6 +175,7 @@ function connectWebSocket() {
if (msg.type === 'server') {
serverDashboard.value = msg.data
fetchLocationStats()
}
} catch (err) {
console.error('[WS] Parse error:', err)
@@ -214,6 +228,7 @@ function navigateTo(path: string) {
onMounted(() => {
connectWebSocket()
updateCurrentTime()
fetchLocationStats()
timeInterval = window.setInterval(updateCurrentTime, 1000)
})
@@ -239,7 +254,7 @@ onUnmounted(() => {
.dashboard-layout { display: flex; gap: 16px; height: 100%; }
.server-section { flex: 9; min-width: 0; }
.network-section { flex: 1; min-width: 130px; max-width: 160px; display: flex; flex-direction: column; gap: 12px; }
.network-section { flex: 1; min-width: 140px; max-width: 180px; display: flex; flex-direction: column; gap: 10px; }
.connection-status { position: fixed; bottom: 16px; right: 16px; padding: 8px 12px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 8px; font-size: 12px; color: var(--text-muted); }
.connection-status.connected { color: #16a34a; }