MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / createSyntheticGroup

Method createSyntheticGroup

internal/ui/components/app.go:672–734  ·  view source on GitHub ↗

createSyntheticGroup creates a synthetic cluster object from a list of nodes for group display.

(nodes []*api.Node)

Source from the content-addressed store, hash-verified

670
671// createSyntheticGroup creates a synthetic cluster object from a list of nodes for group display.
672func (a *App) createSyntheticGroup(nodes []*api.Node) *api.Cluster {
673 cluster := &api.Cluster{
674 Name: fmt.Sprintf("Group: %s", a.groupName),
675 Nodes: nodes,
676 Quorate: true, // Assumed for group view
677 }
678
679 // Calculate totals
680 var totalCPU, totalMem, usedMem float64
681 var onlineNodes int
682 var cpuUsageSum float64
683 var nodesWithMetrics int
684 var totalStorage, usedStorage int64
685
686 uiLogger := models.GetUILogger()
687
688 for _, node := range nodes {
689 if node == nil {
690 continue
691 }
692 if node.Online {
693 onlineNodes++
694
695 // Debug log to check if metrics are populated
696 if node.CPUCount == 0 && node.MemoryTotal == 0 {
697 uiLogger.Debug("Group Stats: Node %s is online but has 0 CPU/Mem. SourceProfile: %s", node.Name, node.SourceProfile)
698 }
699
700 if node.CPUCount > 0 {
701 totalCPU += node.CPUCount
702 totalMem += node.MemoryTotal
703 usedMem += node.MemoryUsed
704 cpuUsageSum += node.CPUUsage
705 nodesWithMetrics++
706 }
707
708 if cluster.Version == "" && node.Version != "" {
709 cluster.Version = fmt.Sprintf("Proxmox VE %s", node.Version)
710 }
711
712 // Convert GB to Bytes for cluster totals (Node struct stores storage in GB)
713 totalStorage += node.TotalStorage * 1024 * 1024 * 1024
714 usedStorage += node.UsedStorage * 1024 * 1024 * 1024
715 }
716 }
717
718 cluster.TotalNodes = len(nodes)
719 cluster.OnlineNodes = onlineNodes
720 cluster.TotalCPU = totalCPU
721 cluster.MemoryTotal = totalMem
722 cluster.MemoryUsed = usedMem
723 if nodesWithMetrics > 0 {
724 cluster.CPUUsage = cpuUsageSum / float64(nodesWithMetrics)
725 }
726
727 cluster.StorageTotal = totalStorage
728 cluster.StorageUsed = usedStorage
729

Callers 4

autoRefreshDataMethod · 0.95
switchToGroupMethod · 0.95
getDisplayClusterMethod · 0.95

Calls 2

GetUILoggerFunction · 0.92
DebugMethod · 0.65

Tested by

no test coverage detected