From 5deb055565606c94fc29bd594832586f3dfdf3de Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 2 Aug 2022 10:07:17 +0200 Subject: fix(web/runner): Prevent reporting NaN values This change fixes an issue with the OpenDC web runner where it would report NaN values for some of the metrics due to the topology being empty. This in turn causes issues in the frontend. --- .../main/kotlin/org/opendc/web/runner/internal/WebComputeMonitor.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/internal/WebComputeMonitor.kt b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/internal/WebComputeMonitor.kt index 01002c70..4c3d1cfa 100644 --- a/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/internal/WebComputeMonitor.kt +++ b/opendc-web/opendc-web-runner/src/main/kotlin/org/opendc/web/runner/internal/WebComputeMonitor.kt @@ -105,9 +105,9 @@ internal class WebComputeMonitor : ComputeMonitor { hostAggregateMetrics.totalIdleTime, hostAggregateMetrics.totalStealTime, hostAggregateMetrics.totalLostTime, - hostMetrics.map { it.value.cpuUsage / it.value.count }.average(), - hostMetrics.map { it.value.cpuDemand / it.value.count }.average(), - hostMetrics.map { it.value.instanceCount.toDouble() / it.value.count }.average(), + hostMetrics.map { it.value.cpuUsage / it.value.count }.average().let { if (it.isNaN()) 0.0 else it }, + hostMetrics.map { it.value.cpuDemand / it.value.count }.average().let { if (it.isNaN()) 0.0 else it }, + hostMetrics.map { it.value.instanceCount.toDouble() / it.value.count }.average().let { if (it.isNaN()) 0.0 else it }, hostMetrics.map { it.value.instanceCount.toDouble() / it.value.count }.maxOrNull() ?: 0.0, hostAggregateMetrics.totalPowerDraw, hostAggregateMetrics.totalFailureSlices.roundToLong(), -- cgit v1.2.3