0

Can we add a powerModel for virtual machine also as we do it for host in Cloudsim (simulation Tool)? So that we can track the power consumption of each virtual machines.

halfer
  • 19,824
  • 17
  • 99
  • 186
mike
  • 13
  • 5

1 Answers1

0

Using CloudSim Plus you can compute the CPU usage and power consumption of a VM using the following code into your example:

private void printVmsCpuUtilizationAndPowerConsumption() {
    for (Vm vm : vmList) {
        System.out.println("Vm " + vm.getId() + " at Host " + vm.getHost().getId() + " CPU Usage and Power Consumption");
        double vmPower; //watt-sec
        double utilizationHistoryTimeInterval, prevTime = 0;
        final UtilizationHistory history = vm.getUtilizationHistory();
        for (final double time : history.getHistory().keySet()) {
            utilizationHistoryTimeInterval = time - prevTime;
            vmPower = history.powerConsumption(time);
            final double wattsPerInterval = vmPower*utilizationHistoryTimeInterval;
            System.out.printf(
                "\tTime %8.1f | Host CPU Usage: %6.1f%% | Power Consumption: %8.0f Watt-Sec * %6.0f Secs = %10.2f Watt-Sec\n",
                time, history.vmCpuUsageFromHostCapacity(time) *100, vmPower, utilizationHistoryTimeInterval, wattsPerInterval);
            prevTime = time;
        }
        System.out.println();
    }
}

You don't implement specific PowerModel for VMs. The VM power consumption is determined by its CPU utilization and the Host's PowerModel.

You can get the complete example here.

Manoel Campos
  • 933
  • 9
  • 12
  • Thank you for this code. I was literally frustrated and was not able to calculate the power consumption. Can you also please suggest a solution of how to get the history of RAM Utilization and Bandwidth Utilization. It would be a great help. – mike Mar 23 '19 at 07:07