From 178cf9a126f0eca1c87fee76ed7f02da1f7dd83d Mon Sep 17 00:00:00 2001 From: Safae Ajib Date: Fri, 20 Sep 2024 11:51:23 +0200 Subject: [PATCH 1/2] Issue #368: KM module: issues with the VM class --- .../engine/strategy/utils/MappingProcessor.java | 2 +- .../os/SuperConnectorOsIT/expected/expected.json | 12 ++++++------ .../sustainability/VmPowerAndEnergyEstimator.java | 7 +------ .../metricshub/hardware/util/HwConstants.java | 2 +- .../os/SuperConnectorOsIT/expected/expected.json | 12 ++++++------ 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/strategy/utils/MappingProcessor.java b/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/strategy/utils/MappingProcessor.java index b18a3f69f..091588caa 100644 --- a/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/strategy/utils/MappingProcessor.java +++ b/metricshub-engine/src/main/java/org/sentrysoftware/metricshub/engine/strategy/utils/MappingProcessor.java @@ -270,7 +270,7 @@ private void processKeyValue(final String key, final String value, final Map= 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); @@ -112,11 +108,10 @@ 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, - HW_VM_POWER_SHARE_METRIC, + "hw.vm.power_ratio", powerShareRatio, telemetryManager.getStrategyTime() ); diff --git a/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/util/HwConstants.java b/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/util/HwConstants.java index 92fe16daf..667b863c0 100644 --- a/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/util/HwConstants.java +++ b/metricshub-hardware/src/main/java/org/sentrysoftware/metricshub/hardware/util/HwConstants.java @@ -59,7 +59,7 @@ public class HwConstants { public static final String HW_POWER_VM_METRIC = "hw.power{hw.type=\"vm\"}"; public static final String POWER_SOURCE_ID_ATTRIBUTE = "__power_source_id"; public static final String HW_VM_POWER_SHARE_METRIC = "__hw.vm.power_ratio.raw_power_share"; - public static final String HW_VM_POWER_STATE_METRIC = "hw.vm.power_state"; + public static final String HW_VM_POWER_STATE_METRIC = "hw.power_state{hw.type=\"vm\"}"; public static final String HW_ENCLOSURE_POWER = "hw.enclosure.power"; public static final String HW_ENCLOSURE_ENERGY = "hw.enclosure.energy"; diff --git a/metricshub-oscommand-extension/src/it/resources/os/SuperConnectorOsIT/expected/expected.json b/metricshub-oscommand-extension/src/it/resources/os/SuperConnectorOsIT/expected/expected.json index e501497ae..85aade742 100644 --- a/metricshub-oscommand-extension/src/it/resources/os/SuperConnectorOsIT/expected/expected.json +++ b/metricshub-oscommand-extension/src/it/resources/os/SuperConnectorOsIT/expected/expected.json @@ -52313,8 +52313,8 @@ "is_endpoint" : false }, { "metrics" : { - "hw.vm.power_ratio.raw_power_share" : { - "name" : "hw.vm.power_ratio.raw_power_share", + "__hw.vm.power_ratio.raw_power_share" : { + "name" : "__hw.vm.power_ratio.raw_power_share", "collectTime" : 1709803030590, "previousCollectTime" : null, "attributes" : { }, @@ -52359,8 +52359,8 @@ "is_endpoint" : false }, { "metrics" : { - "hw.vm.power_ratio.raw_power_share" : { - "name" : "hw.vm.power_ratio.raw_power_share", + "__hw.vm.power_ratio.raw_power_share" : { + "name" : "__hw.vm.power_ratio.raw_power_share", "collectTime" : 1709803030590, "previousCollectTime" : null, "attributes" : { }, @@ -52405,8 +52405,8 @@ "is_endpoint" : false }, { "metrics" : { - "hw.vm.power_ratio.raw_power_share" : { - "name" : "hw.vm.power_ratio.raw_power_share", + "__hw.vm.power_ratio.raw_power_share" : { + "name" : "__hw.vm.power_ratio.raw_power_share", "collectTime" : 1709803030590, "previousCollectTime" : null, "attributes" : { }, From 6750adb5ab70f733e35d71d87e509b2d09489827 Mon Sep 17 00:00:00 2001 From: Safae Ajib Date: Fri, 20 Sep 2024 12:27:28 +0200 Subject: [PATCH 2/2] Issue #368: KM module: issues with the VM class --- .../hardware/sustainability/VmPowerAndEnergyEstimator.java | 4 ++++ 1 file changed, 4 insertions(+) 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,