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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4fda0c0  CLOUDSTACK-9998: Fix metrics generation failurein prometheus 
exporter (#2325)
4fda0c0 is described below

commit 4fda0c039e4c24d399b2952b74ded287ec5a576a
Author: Rohit Yadav <bhais...@apache.org>
AuthorDate: Thu Nov 16 10:13:53 2017 +0530

    CLOUDSTACK-9998: Fix metrics generation failurein prometheus exporter 
(#2325)
    
    This fixes metrics generation failures when metrics capacities are null.
    
    Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
---
 .../cloudstack/metrics/PrometheusExporterImpl.java  | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git 
a/plugins/integrations/prometheus/src/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
 
b/plugins/integrations/prometheus/src/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
index a51b296..92c128b 100644
--- 
a/plugins/integrations/prometheus/src/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
+++ 
b/plugins/integrations/prometheus/src/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
@@ -114,13 +114,23 @@ public class PrometheusExporterImpl extends ManagerBase 
implements PrometheusExp
 
             final String cpuFactor = 
String.valueOf(CapacityManager.CpuOverprovisioningFactor.valueIn(host.getClusterId()));
             final CapacityVO cpuCapacity = 
capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU);
-            metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, 
cpuCapacity.getUsedCapacity()));
-            metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, 
cpuCapacity.getTotalCapacity()));
+            if (cpuCapacity != null) {
+                metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, 
cpuCapacity.getUsedCapacity()));
+                metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, 
cpuCapacity.getTotalCapacity()));
+            } else {
+                metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, USED, 
0L));
+                metricsList.add(new ItemHostCpu(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), cpuFactor, TOTAL, 
0L));
+            }
 
             final String memoryFactor = 
String.valueOf(CapacityManager.MemOverprovisioningFactor.valueIn(host.getClusterId()));
             final CapacityVO memCapacity = 
capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
-            metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, 
memCapacity.getUsedCapacity()));
-            metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, 
TOTAL, memCapacity.getTotalCapacity()));
+            if (memCapacity != null) {
+                metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, 
memCapacity.getUsedCapacity()));
+                metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, 
TOTAL, memCapacity.getTotalCapacity()));
+            } else {
+                metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, USED, 
0L));
+                metricsList.add(new ItemHostMemory(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), memoryFactor, 
TOTAL, 0L));
+            }
 
             metricsList.add(new ItemHostVM(zoneName, zoneUuid, host.getName(), 
host.getUuid(), host.getPrivateIpAddress(), 
vmDao.listByHostId(host.getId()).size()));
 
@@ -128,6 +138,9 @@ public class PrometheusExporterImpl extends ManagerBase 
implements PrometheusExp
             if (coreCapacity != null) {
                 metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), USED, 
coreCapacity.getUsedCapacity()));
                 metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), TOTAL, 
coreCapacity.getTotalCapacity()));
+            } else {
+                metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), USED, 0L));
+                metricsList.add(new ItemVMCore(zoneName, zoneUuid, 
host.getName(), host.getUuid(), host.getPrivateIpAddress(), TOTAL, 0L));
             }
         }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@cloudstack.apache.org" <commits@cloudstack.apache.org>'].

Reply via email to