Files
system-monitor/frontend/components/LocationStatsPortlet.vue
2025-12-28 17:35:46 +09:00

161 lines
3.6 KiB
Vue

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