This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.18 by this push:
     new a20ab40b674 Ensure getCapacityState() is not called for hosts in 
maintenance (#8025)
a20ab40b674 is described below

commit a20ab40b674b313fafc3b4cb18f938107324c16a
Author: Ben <[email protected]>
AuthorDate: Fri Oct 6 03:49:57 2023 -0400

    Ensure getCapacityState() is not called for hosts in maintenance (#8025)
---
 .../cloudstack/metrics/PrometheusExporterImpl.java   | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git 
a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
 
b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
index 171df354616..b44b888b7c2 100644
--- 
a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
+++ 
b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
@@ -163,7 +163,12 @@ public class PrometheusExporterImpl extends ManagerBase 
implements PrometheusExp
             final CapacityVO cpuCapacity = 
capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU);
             final double cpuUsedMhz = hostStats.getCpuUtilization() * 
host.getCpus() * host.getSpeed() / 100.0 ;
 
-            if (cpuCapacity != null && cpuCapacity.getCapacityState() == 
CapacityState.Enabled) {
+            if (host.isInMaintenanceStates()) {
+                metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, 
ALLOCATED, 0L, isDedicated, hostTags));
+                metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, 
0L, isDedicated, hostTags));
+                metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, 
0L, isDedicated, hostTags));
+            }
+            else if (cpuCapacity != null && cpuCapacity.getCapacityState() == 
CapacityState.Enabled) {
                 metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, 
ALLOCATED, cpuCapacity.getUsedCapacity(), isDedicated, hostTags));
                 metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, 
cpuUsedMhz, isDedicated, hostTags));
                 metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, 
cpuCapacity.getTotalCapacity(), isDedicated, hostTags));
@@ -175,7 +180,12 @@ public class PrometheusExporterImpl extends ManagerBase 
implements PrometheusExp
 
             final String memoryFactor = 
String.valueOf(CapacityManager.MemOverprovisioningFactor.valueIn(host.getClusterId()));
             final CapacityVO memCapacity = 
capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
-            if (memCapacity != null && memCapacity.getCapacityState() == 
CapacityState.Enabled) {
+            if (host.isInMaintenanceStates()) {
+                metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, 
ALLOCATED, 0L, isDedicated, hostTags));
+                metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, 
0, isDedicated, hostTags));
+                metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, 
TOTAL, 0L, isDedicated, hostTags));
+            }
+            else if (memCapacity != null && memCapacity.getCapacityState() == 
CapacityState.Enabled) {
                 metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, 
ALLOCATED, memCapacity.getUsedCapacity(), isDedicated, hostTags));
                 metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, 
hostStats.getUsedMemory(), isDedicated, hostTags));
                 metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, 
TOTAL, memCapacity.getTotalCapacity(), isDedicated, hostTags));
@@ -188,7 +198,11 @@ public class PrometheusExporterImpl extends ManagerBase 
implements PrometheusExp
             metricsList.add(new ItemHostVM(zoneName, zoneUuid, host.getName(), 
host.getUuid(), host.getPrivateIpAddress(), 
vmDao.listByHostId(host.getId()).size()));
 
             final CapacityVO coreCapacity = 
capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU_CORE);
-            if (coreCapacity != null && coreCapacity.getCapacityState() == 
CapacityState.Enabled) {
+            if (host.isInMaintenanceStates()) {
+                metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), USED, 0L, 
isDedicated, hostTags));
+                metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), TOTAL, 0L, 
isDedicated, hostTags));
+            }
+            else if (coreCapacity != null && coreCapacity.getCapacityState() 
== CapacityState.Enabled) {
                 metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), USED, 
coreCapacity.getUsedCapacity(), isDedicated, hostTags));
                 metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), TOTAL, 
coreCapacity.getTotalCapacity(), isDedicated, hostTags));
             } else {

Reply via email to