diff --git a/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/sustainability/VmPowerAndEnergyEstimator.java b/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/sustainability/VmPowerAndEnergyEstimator.java index 8040c37ef..4000aa166 100644 --- a/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/sustainability/VmPowerAndEnergyEstimator.java +++ b/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/sustainability/VmPowerAndEnergyEstimator.java @@ -69,13 +69,16 @@ public VmPowerAndEnergyEstimator( protected Double doPowerEstimation() { // Get the vm power share, always >= 0.0 here final double vmPowerShare = HwCollectHelper.getVmPowerShare(monitor); + // Getting the VM's power share ratio final String powerSourceId = monitor.getAttribute(POWER_SOURCE_ID_ATTRIBUTE); final Double totalPowerShares = totalPowerSharesByPowerSource.get(powerSourceId); + // totalPowerShares is never null here because the VM always comes with a powerShare value final double powerShareRatio = totalPowerShares != null && totalPowerShares > 0.0 ? vmPowerShare / totalPowerShares : 0.0; + // Getting the power source's power consumption value final Monitor powerSourceMonitor = telemetryManager.findMonitorById(powerSourceId); @@ -108,6 +111,7 @@ protected Double doPowerEstimation() { if (powerSourcePowerConsumption != null && powerSourcePowerConsumption >= 0.0) { estimatedPower = NumberHelper.round(powerSourcePowerConsumption * powerShareRatio, 2, RoundingMode.HALF_UP); } + final MetricFactory metricFactory = new MetricFactory(telemetryManager.getHostname()); metricFactory.collectNumberMetric( monitor,