Calculate the average resources utilized by each Host in a Datacenter

  • These resources decreases when each VM allocated to a Host. The formula for average utilization is:

     avgUtilization = (initialResource – availableResource / initialResource ) *  100

  • initialResources= initalMips, initialRam, initialBandwidth assigned for the HostavailableResources=availableMips, availableRam, availableBandwidth in each host after the vm is allocated.

Example:

  • Let mips, bandwidth, store are the initial resources which are assigned in the Host creation step itself. (in creating cloud environment steps, refer step 2)

  • Let “host” be the Host object

  • get the host list

    getHostList();</p>

    int size=getHostList().size();

  • create array to store the utilization values of CPU, bandwidth and storage.

    double[] avgCPU           = new double[size];</p>

    double[] avgBandwidth = new double[size];

    double[] avgStorage      = new double[size];

  • get the available resources of each host

    for(int i=0;i<size;i++){</p>

    host = getHostList().get(j); // get each Host from the list

    int hid = host.getId();

    double availmip = host.getAvailableMips(); //retrieves the available Cpu capacity

    long band = host.getBw(); //retrieves the available Bandwidth capacity

    long st = host.getStorage(); //retrieves the available Storage capacity

  • convert all long data types to double.

    Long l1=band;</p>

    availband=l1.doubleValue(); //long->double conversion

    Long l2=st;

    availstore=l2.doubleValue();

    avgCPU[i] = ((mips – availmip ) / (mips)) * 100

    avgBandwidth [i] = ((bandwidth- availband) / (bandwidth)) * 100

    avgStorage[i] = ((store – availstore) / (store)) * 100

    }