Module: VSphereMonitoring
- Defined in:
- lib/vspheremonitoring.rb
Class Method Summary collapse
- .cluster_cpu(cluster) ⇒ Object
- .cluster_memory(cluster) ⇒ Object
- .cluster_stats(cluster) ⇒ Object
- .datastore_stats(datastore) ⇒ Object
- .host_cpu(host) ⇒ Object
- .host_memory(host) ⇒ Object
- .host_stats(host) ⇒ Object
- .network_stats(network) ⇒ Object
- .process_all_datacenters(datacenterlist, vim) ⇒ Object
- .process_datacenter(dc) ⇒ Object
Class Method Details
.cluster_cpu(cluster) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/vspheremonitoring.rb', line 42 def cluster_cpu (cluster) data = Hash.new data['totalCpu'] = cluster.summary.totalCpu data['numCpuCores'] = cluster.summary.numCpuCores data['numCpuThreads'] = cluster.summary.numCpuThreads data['effectiveCpu'] = cluster.summary.effectiveCpu data end |
.cluster_memory(cluster) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/vspheremonitoring.rb', line 35 def cluster_memory (cluster) data = Hash.new data['totalMemory'] = cluster.summary.totalMemory data['effectiveMemory'] = cluster.summary.effectiveMemory data end |
.cluster_stats(cluster) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vspheremonitoring.rb', line 51 def cluster_stats (cluster) data = Hash.new data['cpu'] = cluster_cpu(cluster) data['memory'] = cluster_memory(cluster) data['numVmotions'] = cluster.summary.numVmotions data['numHosts'] = cluster.summary.numHosts data['numEffectiveHosts'] = cluster.summary.numEffectiveHosts data['targetBalance'] = cluster.summary.targetBalance data['currentBalance'] = cluster.summary.currentBalance data end |
.datastore_stats(datastore) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vspheremonitoring.rb', line 63 def datastore_stats (datastore) data = Hash.new datastore.RefreshDatastore capacity = datastore.summary.capacity freeSpace = datastore.summary.freeSpace uncommitted = datastore.summary.uncommitted data['capacityM'] = ((capacity / 1024) / 1024) if capacity.class != NilClass data['freeSpaceM'] = ((freeSpace / 1024) / 1024) if freeSpace.class != NilClass data['uncommittedM'] = ((uncommitted / 1024) / 1024) if uncommitted.class != NilClass data end |
.host_cpu(host) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/vspheremonitoring.rb', line 18 def host_cpu (host) data = Hash.new data['Mhz'] = host.hardware.cpuInfo.hz / 1000 / 1000 data['cores'] = host.hardware.cpuInfo.numCpuCores data['totalMhz'] = data['Mhz'] * data['cores'] data['usageMhz'] = host.summary.quickStats.overallCpuUsage.to_f data['percent'] = (data['usageMhz'] / data['totalMhz']) * 100 data end |
.host_memory(host) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/vspheremonitoring.rb', line 10 def host_memory (host) data = Hash.new data['total'] = host.hardware.memorySize.bytes.to.megabytes.to_f data['usage'] = host.summary.quickStats.overallMemoryUsage.megabytes.to_f data['percent'] = (data['usage'] / data['total']) * 100 data end |
.host_stats(host) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/vspheremonitoring.rb', line 28 def host_stats (host) data = Hash.new data['memory'] = host_memory(host) data['cpu'] = host_cpu(host) data end |
.network_stats(network) ⇒ Object
75 76 77 78 |
# File 'lib/vspheremonitoring.rb', line 75 def network_stats (network) data = Hash.new data end |
.process_all_datacenters(datacenterlist, vim) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/vspheremonitoring.rb', line 110 def process_all_datacenters (datacenterlist,vim) data = Hash.new datacenterlist.each do |datacenter| dc = vim.serviceInstance.find_datacenter datacenter data[dc.name] = VSphereMonitoring.process_datacenter(dc) end data end |
.process_datacenter(dc) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/vspheremonitoring.rb', line 80 def process_datacenter (dc) data = Hash.new data['hypers'] = Hash.new data['clusters'] = Hash.new data['datastores'] = Hash.new # Get the information for host host_list = dc.hostFolder.children.select {|h| h.class == RbVmomi::VIM::ComputeResource } host_list.map {|h| data['hypers'][h.name] = host_stats(h.host.first) } # Get the information for each host in a cluster cluster_list = dc.hostFolder.children.select {|h| h.class == RbVmomi::VIM::ClusterComputeResource } cluster_list.map {|c| data['clusters'][c.name] = cluster_stats(c) c.host.map {|h| data['hypers'][h.name] = host_stats(h) } } # Get informaton about datastore usage datastore_list = dc.datastore datastore_list.map {|d| data['datastores'][d.name] = datastore_stats(d) } data['vm_count'] = dc.vmFolder.children.select {|v| v.class == RbVmomi::VIM::VirtualMachine }.size data end |