Skip to content

Commit

Permalink
Issue #368: KM module: issues with the VM class
Browse files Browse the repository at this point in the history
  • Loading branch information
SafaeAJ committed Sep 20, 2024
1 parent e3f9b23 commit 6750adb
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6750adb

Please sign in to comment.