bosh_vsphere_cpi/lib/cloud/vsphere/resources/cluster.rb
def fetch_cluster_utilization(host_mobs)
        hosts_properties = @client.get_properties(
            host_mobs, Vim::HostSystem, HOST_PROPERTIES, :ensure_all => true)
        host_mobs = filter_inactive_hosts(hosts_properties)

        if host_mobs.empty?
          @idle_cpu = 0
          @total_memory = 0
          @synced_free_memory = 0
          return
        end

        samples = 0
        cluster_total_memory = 0
        cluster_free_memory = 0
        cluster_cpu_usage = 0

        counters = @client.get_perf_counters(
            host_mobs, HOST_COUNTERS, :max_sample => 5)
        counters.each do |host_mob, counter|
          host_properties = hosts_properties[host_mob]
          total_memory = host_properties["hardware.memorySize"].to_i
          percent_used = Util.average_csv(counter["mem.usage.average"]) / 10000
          free_memory = ((1.0 - percent_used) * total_memory).to_i

          samples += 1
          cluster_total_memory += total_memory
          cluster_free_memory += free_memory
          cluster_cpu_usage +=
              Util.average_csv(counter["cpu.usage.average"]) / 100
        end

        @idle_cpu = (100 - cluster_cpu_usage / samples) / 100
        @total_memory = cluster_total_memory / BYTES_IN_MB
        @synced_free_memory = cluster_free_memory / BYTES_IN_MB
      end
# Fetches the raw cluster utilization from vSphere.
#
# First filter out any hosts that are in maintenance mode. Then aggregate
# individual host capacity and its utilization using the performance
# manager.
#
# @param [Array<Vim::HostSystem>] host_mobs cluster hosts.
# @return [void]
Fetches the raw cluster utilization from vSphere.
First filter out any hosts that are in maintenance mode. Then aggregate
individual host capacity and its utilization using the performance
manager.
Fetches the raw cluster utilization from vSphere . First filter out any hosts that are in maintenance mode . Then aggregate individual host capacity and its utilization using the performance manager .
def fetch_cluster_utilization(host_mobs)
        hosts_properties = @client.get_properties(
            host_mobs, Vim::HostSystem, HOST_PROPERTIES, :ensure_all => true)
        host_mobs = filter_inactive_hosts(hosts_properties)
        if host_mobs.empty?
          @idle_cpu = 0
          @total_memory = 0
          @synced_free_memory = 0
          return
        end
        samples = 0
        cluster_total_memory = 0
        cluster_free_memory = 0
        cluster_cpu_usage = 0
        counters = @client.get_perf_counters(
            host_mobs, HOST_COUNTERS, :max_sample => 5)
        counters.each do |host_mob, counter|
          host_properties = hosts_properties[host_mob]
          total_memory = host_properties["hardware.memorySize"].to_i
          percent_used = Util.average_csv(counter["mem.usage.average"]) / 10000
          free_memory = ((1.0 - percent_used) * total_memory).to_i
          samples += 1
          cluster_total_memory += total_memory
          cluster_free_memory += free_memory
          cluster_cpu_usage +=
              Util.average_csv(counter["cpu.usage.average"]) / 100
        end
        @idle_cpu = (100 - cluster_cpu_usage / samples) / 100
        @total_memory = cluster_total_memory / BYTES_IN_MB
        @synced_free_memory = cluster_free_memory / BYTES_IN_MB
      end
def fetch_cluster_utilization ( host_mobs ) hosts_properties = @client . get_properties ( host_mobs , Vim :: HostSystem , HOST_PROPERTIES , :ensure_all => true ) host_mobs = filter_inactive_hosts ( hosts_properties ) if host_mobs . empty? @idle_cpu = 0 @total_memory = 0 @synced_free_memory = 0 return end samples = 0 cluster_total_memory = 0 cluster_free_memory = 0 cluster_cpu_usage = 0 counters = @client . get_perf_counters ( host_mobs , HOST_COUNTERS , :max_sample => 5 ) counters . each do | host_mob , counter | host_properties = hosts_properties [ host_mob ] total_memory = host_properties [ "hardware.memorySize" ] . to_i percent_used = Util . average_csv ( counter [ "mem.usage.average" ] ) / 10000 free_memory = ( ( 1.0 - percent_used ) * total_memory ) . to_i samples += 1 cluster_total_memory += total_memory cluster_free_memory += free_memory cluster_cpu_usage += Util . average_csv ( counter [ "cpu.usage.average" ] ) / 100 end @idle_cpu = ( 100 - cluster_cpu_usage / samples ) / 100 @total_memory = cluster_total_memory / BYTES_IN_MB @synced_free_memory = cluster_free_memory / BYTES_IN_MB end
Fetches the raw cluster utilization from vSphere.
Fetches the raw cluster utilization from vSphere .
None
void
host_mobs
host_mobs cluster hosts.
host_mobs cluster hosts .