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

Method GetNodeStatus

pkg/api/node.go:80–176  ·  view source on GitHub ↗

GetNodeStatus retrieves real-time status for a specific node.

(nodeName string)

Source from the content-addressed store, hash-verified

78
79// GetNodeStatus retrieves real-time status for a specific node.
80func (c *Client) GetNodeStatus(nodeName string) (*Node, error) {
81 var res map[string]interface{}
82
83 if err := c.GetWithCache(fmt.Sprintf("/nodes/%s/status", nodeName), &res, NodeDataTTL); err != nil {
84 return nil, fmt.Errorf("failed to get status for node %s: %w", nodeName, err)
85 }
86
87 // config.DebugLog("[DEBUG] Raw node status response: %+v", res) // Log raw API response
88
89 data, ok := res["data"].(map[string]interface{})
90 if !ok {
91 return nil, fmt.Errorf("invalid status response format for node %s", nodeName)
92 }
93
94 // config.DebugLog("[DEBUG] Parsed node status data: %+v", data) // Log parsed data structure
95
96 node := &Node{
97 ID: nodeName,
98 Name: nodeName,
99 Online: strings.EqualFold(getString(data, "status"), "online"),
100 CPUUsage: getFloat(data, "cpu"),
101 KernelVersion: getString(data, "kversion"),
102 Version: getString(data, "pveversion"),
103 }
104
105 // Get CPU count from cpuinfo
106 if cpuinfo, ok := data["cpuinfo"].(map[string]interface{}); ok {
107 node.CPUCount = getFloat(cpuinfo, "cpus")
108 }
109
110 // Get memory stats
111 if memory, ok := data["memory"].(map[string]interface{}); ok {
112 node.MemoryTotal = getFloat(memory, "total") / 1073741824
113 node.MemoryUsed = getFloat(memory, "used") / 1073741824
114 }
115
116 // Get storage stats (convert bytes to GB for consistency with cluster data)
117 if rootfs, ok := data["rootfs"].(map[string]interface{}); ok {
118 node.TotalStorage = int64(getFloat(rootfs, "total") / 1073741824)
119 node.UsedStorage = int64(getFloat(rootfs, "used") / 1073741824)
120 }
121
122 // Get uptime
123 node.Uptime = int64(getFloat(data, "uptime"))
124
125 // Parse CPU info with safe type conversion
126 if cpuinfoData, ok := data["cpuinfo"].(map[string]interface{}); ok {
127 cpuInfo := &CPUInfo{}
128 if cores, ok := cpuinfoData["cores"].(float64); ok {
129 cpuInfo.Cores = int(cores)
130 }
131
132 if cpus, ok := cpuinfoData["cpus"].(float64); ok {
133 cpuInfo.Cpus = int(cpus)
134 }
135
136 if model, ok := cpuinfoData["model"].(string); ok {
137 cpuInfo.Model = model

Callers 4

RefreshNodeDataMethod · 0.95
TestPVEMockAPIFunction · 0.95
GetNodeFromGroupMethod · 0.80

Calls 3

GetWithCacheMethod · 0.95
getStringFunction · 0.85
getFloatFunction · 0.85

Tested by 1

TestPVEMockAPIFunction · 0.76