Skip to content

Commit

Permalink
Added the option to select which files to export. (#307)
Browse files Browse the repository at this point in the history
* Added the option to select which files to export.

* Updated documentation
  • Loading branch information
DanteNiewenhuis authored Feb 18, 2025
1 parent e9080b6 commit ee770ff
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package org.opendc.compute.simulator.provisioner
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.simulator.telemetry.ComputeMetricReader
import org.opendc.compute.simulator.telemetry.ComputeMonitor
import org.opendc.compute.simulator.telemetry.OutputFiles
import java.time.Duration

/**
Expand All @@ -36,6 +37,14 @@ public class ComputeMonitorProvisioningStep(
private val monitor: ComputeMonitor,
private val exportInterval: Duration,
private val startTime: Duration = Duration.ofMillis(0),
private val filesToExport: Map<OutputFiles, Boolean> =
mapOf(
OutputFiles.HOST to true,
OutputFiles.TASK to true,
OutputFiles.SERVICE to true,
OutputFiles.POWER_SOURCE to true,
OutputFiles.BATTERY to true,
),
) : ProvisioningStep {
override fun apply(ctx: ProvisioningContext): AutoCloseable {
val service =
Expand All @@ -49,6 +58,7 @@ public class ComputeMonitorProvisioningStep(
monitor,
exportInterval,
startTime,
filesToExport,
)
return metricReader
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package org.opendc.compute.simulator.provisioner

import org.opendc.compute.simulator.scheduler.ComputeScheduler
import org.opendc.compute.simulator.telemetry.ComputeMonitor
import org.opendc.compute.simulator.telemetry.OutputFiles
import org.opendc.compute.topology.specs.ClusterSpec
import org.opendc.compute.topology.specs.HostSpec
import java.time.Duration
Expand Down Expand Up @@ -59,8 +60,16 @@ public fun registerComputeMonitor(
monitor: ComputeMonitor,
exportInterval: Duration = Duration.ofMinutes(5),
startTime: Duration = Duration.ofMillis(0),
filesToExport: Map<OutputFiles, Boolean> =
mapOf(
OutputFiles.HOST to true,
OutputFiles.TASK to true,
OutputFiles.SERVICE to true,
OutputFiles.POWER_SOURCE to true,
OutputFiles.BATTERY to true,
),
): ProvisioningStep {
return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime)
return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime, filesToExport)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public class ComputeMetricReader(
private val monitor: ComputeMonitor,
private val exportInterval: Duration = Duration.ofMinutes(5),
private val startTime: Duration = Duration.ofMillis(0),
private val toMonitor: Map<OutputFiles, Boolean> =
mapOf(
OutputFiles.HOST to true,
OutputFiles.TASK to true,
OutputFiles.POWER_SOURCE to true,
OutputFiles.BATTERY to true,
OutputFiles.SERVICE to true,
),
) : AutoCloseable {
private val logger = KotlinLogging.logger {}
private val scope = CoroutineScope(dispatcher.asCoroutineDispatcher())
Expand Down Expand Up @@ -116,68 +124,78 @@ public class ComputeMetricReader(
try {
val now = this.clock.instant()

for (host in this.service.hosts) {
val reader =
this.hostTableReaders.computeIfAbsent(host) {
HostTableReaderImpl(
it,
startTime,
)
}
reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
if (toMonitor[OutputFiles.HOST] == true) {
for (host in this.service.hosts) {
val reader =
this.hostTableReaders.computeIfAbsent(host) {
HostTableReaderImpl(
it,
startTime,
)
}
reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
}
}

for (task in this.service.tasks) {
val reader =
this.taskTableReaders.computeIfAbsent(task) {
TaskTableReaderImpl(
service,
it,
startTime,
)
}
reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
if (toMonitor[OutputFiles.TASK] == true) {
for (task in this.service.tasks) {
val reader =
this.taskTableReaders.computeIfAbsent(task) {
TaskTableReaderImpl(
service,
it,
startTime,
)
}
reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
}
}

for (task in this.service.tasksToRemove) {
task.delete()
}
this.service.clearTasksToRemove()

for (simPowerSource in this.service.powerSources) {
val reader =
this.powerSourceTableReaders.computeIfAbsent(simPowerSource) {
PowerSourceTableReaderImpl(
it,
startTime,
)
}

reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
if (toMonitor[OutputFiles.POWER_SOURCE] == true) {
for (simPowerSource in this.service.powerSources) {
val reader =
this.powerSourceTableReaders.computeIfAbsent(simPowerSource) {
PowerSourceTableReaderImpl(
it,
startTime,
)
}

reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
}
}

for (simBattery in this.service.batteries) {
val reader =
this.batteryTableReaders.computeIfAbsent(simBattery) {
BatteryTableReaderImpl(
it,
startTime,
)
}

reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
if (toMonitor[OutputFiles.BATTERY] == true) {
for (simBattery in this.service.batteries) {
val reader =
this.batteryTableReaders.computeIfAbsent(simBattery) {
BatteryTableReaderImpl(
it,
startTime,
)
}

reader.record(now)
this.monitor.record(reader.copy())
reader.reset()
}
}

this.serviceTableReader.record(now)
monitor.record(this.serviceTableReader.copy())
if (toMonitor[OutputFiles.SERVICE] == true) {
this.serviceTableReader.record(now)
monitor.record(this.serviceTableReader.copy())
}

if (loggCounter >= 100) {
var loggString = "\n\t\t\t\t\tMetrics after ${now.toEpochMilli() / 1000 / 60 / 60} hours:\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2025 AtLarge Research
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.opendc.compute.simulator.telemetry

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
public enum class OutputFiles {
@SerialName("host")
HOST,

@SerialName("task")
TASK,

@SerialName("powerSource")
POWER_SOURCE,

@SerialName("battery")
BATTERY,

@SerialName("service")
SERVICE,
}
Loading

0 comments on commit ee770ff

Please sign in to comment.