Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,30 @@ func (k *KVMResourceCapacityKPI) Collect(ch chan<- prometheus.Metric) {
}

for _, hypervisor := range hvs.Items {
cpuTotal, hasCPUTotal := hypervisor.Status.Capacity["cpu"]
ramTotal, hasRAMTotal := hypervisor.Status.Capacity["memory"]
if hypervisor.Status.EffectiveCapacity == nil {
slog.Warn("hypervisor with nil effective capacity, skipping", "host", hypervisor.Name)
continue
}

cpuTotal, hasCPUTotal := hypervisor.Status.EffectiveCapacity[hv1.ResourceCPU]
ramTotal, hasRAMTotal := hypervisor.Status.EffectiveCapacity[hv1.ResourceMemory]

if !hasCPUTotal || !hasRAMTotal {
slog.Error("hypervisor missing cpu or ram total capacity", "hypervisor", hypervisor.Name)
continue
}

cpuUsed, hasCPUUtilized := hypervisor.Status.Allocation["cpu"]
if cpuTotal.IsZero() || ramTotal.IsZero() {
slog.Warn("hypervisor with zero cpu or ram total capacity, skipping", "host", hypervisor.Name)
continue
}

cpuUsed, hasCPUUtilized := hypervisor.Status.Allocation[hv1.ResourceCPU]
if !hasCPUUtilized {
cpuUsed = resource.MustParse("0")
}

ramUsed, hasRAMUtilized := hypervisor.Status.Allocation["memory"]
ramUsed, hasRAMUtilized := hypervisor.Status.Allocation[hv1.ResourceMemory]
if !hasRAMUtilized {
ramUsed = resource.MustParse("0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestKVMResourceCapacityKPI_Collect(t *testing.T) {
},
},
Status: hv1.HypervisorStatus{
Capacity: map[hv1.ResourceName]resource.Quantity{
EffectiveCapacity: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceCPU: resource.MustParse("128"),
hv1.ResourceMemory: resource.MustParse("512Gi"),
},
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestKVMResourceCapacityKPI_Collect(t *testing.T) {
},
},
Status: hv1.HypervisorStatus{
Capacity: map[hv1.ResourceName]resource.Quantity{
EffectiveCapacity: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceCPU: resource.MustParse("256"),
hv1.ResourceMemory: resource.MustParse("1Ti"),
},
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestKVMResourceCapacityKPI_Collect(t *testing.T) {
},
},
Status: hv1.HypervisorStatus{
Capacity: map[hv1.ResourceName]resource.Quantity{
EffectiveCapacity: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceCPU: resource.MustParse("64"),
hv1.ResourceMemory: resource.MustParse("256Gi"),
},
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestKVMResourceCapacityKPI_Collect(t *testing.T) {
},
},
Status: hv1.HypervisorStatus{
Capacity: map[hv1.ResourceName]resource.Quantity{
EffectiveCapacity: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceCPU: resource.MustParse("100"),
hv1.ResourceMemory: resource.MustParse("200Gi"),
},
Expand All @@ -274,7 +274,7 @@ func TestKVMResourceCapacityKPI_Collect(t *testing.T) {
},
},
Status: hv1.HypervisorStatus{
Capacity: map[hv1.ResourceName]resource.Quantity{
EffectiveCapacity: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceCPU: resource.MustParse("200"),
hv1.ResourceMemory: resource.MustParse("400Gi"),
},
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestKVMResourceCapacityKPI_Collect(t *testing.T) {
},
},
Status: hv1.HypervisorStatus{
Capacity: map[hv1.ResourceName]resource.Quantity{
EffectiveCapacity: map[hv1.ResourceName]resource.Quantity{
hv1.ResourceCPU: resource.MustParse("96"),
hv1.ResourceMemory: resource.MustParse("384Gi"),
},
Expand Down
Loading