Fix handling of node states and data
This commit is contained in:
		| @@ -11,16 +11,18 @@ | ||||
|               <div class="card-body"> | ||||
|                 <h5 class="card-title">{{ node.name }}</h5> | ||||
|                 <p :class="['mb-2', getHealthClass(node.health)]"> | ||||
|                   Health: {{ node.health }}% | ||||
|                   Health: {{ node.health || 0 }}% | ||||
|                 </p> | ||||
|                 <p class="card-text"> | ||||
|                   <strong>State:</strong> {{ node.state }}<br> | ||||
|                   <strong>CPU:</strong> {{ node.cpu_cores }} cores ({{ node.cpu_load }}% load)<br> | ||||
|                   <strong>Memory:</strong> {{ formatMemory(node.memory_used) }}/{{ formatMemory(node.memory_total) }} ({{ node.memory_utilization }}%)<br> | ||||
|                   <strong>VMs:</strong> {{ node.vms.length }} {{ node.vms.length === 1 ? 'VM' : 'VMs' }} | ||||
|                   <strong>Daemon:</strong> {{ node.daemon_state || 'Unknown' }}<br> | ||||
|                   <strong>Coordinator:</strong> {{ node.coordinator_state || 'Unknown' }}<br> | ||||
|                   <strong>Domain:</strong> {{ node.domain_state || 'Unknown' }}<br> | ||||
|                   <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> | ||||
|                 <div v-if="node.vms.length > 0" class="small text-muted"> | ||||
|                   {{ node.vms.join(', ') }} | ||||
|                 <div v-if="(node.vms || []).length > 0" class="small text-muted"> | ||||
|                   {{ (node.vms || []).join(', ') }} | ||||
|                 </div> | ||||
|               </div> | ||||
|             </div> | ||||
| @@ -41,15 +43,41 @@ const props = defineProps({ | ||||
| }); | ||||
|  | ||||
| const getHealthClass = (health) => { | ||||
|   if (!health) return 'status-error'; | ||||
|   if (health > 90) return 'status-healthy'; | ||||
|   if (health > 50) return 'status-warning'; | ||||
|   return 'status-error'; | ||||
| }; | ||||
|  | ||||
| const formatMemory = (bytes) => { | ||||
|   if (bytes === 0) return '0GB'; | ||||
|   const gb = bytes / (1024 * 1024 * 1024); | ||||
|   return `${Math.round(gb)}GB`; | ||||
| const formatMemory = (node) => { | ||||
|   console.log('Memory data for node:', node.name, node.memory); | ||||
|    | ||||
|   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> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user