Fix handling of node states and data
This commit is contained in:
parent
24ddcf5060
commit
303d2d6001
@ -11,16 +11,18 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">{{ node.name }}</h5>
|
<h5 class="card-title">{{ node.name }}</h5>
|
||||||
<p :class="['mb-2', getHealthClass(node.health)]">
|
<p :class="['mb-2', getHealthClass(node.health)]">
|
||||||
Health: {{ node.health }}%
|
Health: {{ node.health || 0 }}%
|
||||||
</p>
|
</p>
|
||||||
<p class="card-text">
|
<p class="card-text">
|
||||||
<strong>State:</strong> {{ node.state }}<br>
|
<strong>Daemon:</strong> {{ node.daemon_state || 'Unknown' }}<br>
|
||||||
<strong>CPU:</strong> {{ node.cpu_cores }} cores ({{ node.cpu_load }}% load)<br>
|
<strong>Coordinator:</strong> {{ node.coordinator_state || 'Unknown' }}<br>
|
||||||
<strong>Memory:</strong> {{ formatMemory(node.memory_used) }}/{{ formatMemory(node.memory_total) }} ({{ node.memory_utilization }}%)<br>
|
<strong>Domain:</strong> {{ node.domain_state || 'Unknown' }}<br>
|
||||||
<strong>VMs:</strong> {{ node.vms.length }} {{ node.vms.length === 1 ? 'VM' : 'VMs' }}
|
<strong>CPU:</strong> {{ node.cpu_count || 0 }} cores ({{ node.load || 0 }}% load)<br>
|
||||||
|
<strong>Memory:</strong> {{ formatMemory(node).used }}GB/{{ formatMemory(node).total }}GB ({{ formatMemory(node).percent }}%)<br>
|
||||||
|
<strong>VMs:</strong> {{ node.domains_count || 0 }} {{ node.domains_count === 1 ? 'VM' : 'VMs' }}
|
||||||
</p>
|
</p>
|
||||||
<div v-if="node.vms.length > 0" class="small text-muted">
|
<div v-if="(node.vms || []).length > 0" class="small text-muted">
|
||||||
{{ node.vms.join(', ') }}
|
{{ (node.vms || []).join(', ') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -41,15 +43,41 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const getHealthClass = (health) => {
|
const getHealthClass = (health) => {
|
||||||
|
if (!health) return 'status-error';
|
||||||
if (health > 90) return 'status-healthy';
|
if (health > 90) return 'status-healthy';
|
||||||
if (health > 50) return 'status-warning';
|
if (health > 50) return 'status-warning';
|
||||||
return 'status-error';
|
return 'status-error';
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatMemory = (bytes) => {
|
const formatMemory = (node) => {
|
||||||
if (bytes === 0) return '0GB';
|
console.log('Memory data for node:', node.name, node.memory);
|
||||||
const gb = bytes / (1024 * 1024 * 1024);
|
|
||||||
return `${Math.round(gb)}GB`;
|
if (!node.memory || typeof node.memory !== 'object') {
|
||||||
|
return { used: 'N/A', total: 'N/A', percent: 'N/A' };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert MB to GB with 2 decimal places
|
||||||
|
const toGB = (mb) => {
|
||||||
|
if (typeof mb !== 'number' || isNaN(mb)) {
|
||||||
|
console.log('Invalid MB value:', mb);
|
||||||
|
return 'N/A';
|
||||||
|
}
|
||||||
|
return (mb / 1024).toFixed(2);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Extract values from the Proxy object
|
||||||
|
const memoryData = Object.assign({}, node.memory);
|
||||||
|
const used = toGB(memoryData.used);
|
||||||
|
const total = toGB(memoryData.total);
|
||||||
|
|
||||||
|
console.log('Converted memory values:', { used, total });
|
||||||
|
|
||||||
|
let percent = 'N/A';
|
||||||
|
if (used !== 'N/A' && total !== 'N/A' && parseFloat(total) > 0) {
|
||||||
|
percent = Math.round((parseFloat(used) / parseFloat(total)) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { used, total, percent };
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user