vspheremonitor 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -0
- data/Rakefile +8 -0
- data/bin/vspheremonitor +47 -0
- data/etc/vsphere.yaml.sample +7 -0
- data/lib/vspheremonitoring.rb +121 -0
- metadata +115 -0
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# VSpereMonitoring
|
2
|
+
|
3
|
+
VSphereMonitor is a tool to get some basic statistics out of a vSphere installation. It uses the VMware Ruby client 'rbvmomi'.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
### Install
|
8
|
+
|
9
|
+
gem install vspheremonitor
|
10
|
+
|
11
|
+
### Basic Execution
|
12
|
+
|
13
|
+
vspheremonitor -c /opt/etc/monitoring/vsphere.yaml
|
14
|
+
|
data/Rakefile
ADDED
data/bin/vspheremonitor
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "vspheremonitoring"
|
5
|
+
require "rbvmomi"
|
6
|
+
require "json"
|
7
|
+
require "yaml"
|
8
|
+
rescue LoadError
|
9
|
+
puts 'Some of the required gems have not been found'
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'optparse'
|
14
|
+
|
15
|
+
options = {}
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: vspheremonitor [options]"
|
18
|
+
|
19
|
+
opts.on("-v", "--verbose", "Be less quiet") do |v|
|
20
|
+
options[:verbose] = v
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("-c", "--config FILE", "Specify the configuration file") do |c|
|
24
|
+
options[:configfile] = c
|
25
|
+
end
|
26
|
+
|
27
|
+
end.parse!
|
28
|
+
|
29
|
+
def run (options)
|
30
|
+
|
31
|
+
configfile = 'etc/vsphere.yaml' if options[:configfile].nil?
|
32
|
+
|
33
|
+
config = YAML::load(File.read(configfile))
|
34
|
+
vim = RbVmomi::VIM.connect :host => config[:host],
|
35
|
+
:user => config[:user],
|
36
|
+
:password => config[:password],
|
37
|
+
:insecure => true
|
38
|
+
|
39
|
+
data = Hash.new
|
40
|
+
data[:vsphere] = VSphereMonitoring.process_all_datacenters(config[:datacenters],vim)
|
41
|
+
data
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
output = run(options)
|
46
|
+
puts output.to_json
|
47
|
+
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rbvmomi'
|
3
|
+
require 'pp'
|
4
|
+
require 'alchemist'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module VSphereMonitoring
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def host_memory (host)
|
11
|
+
data = Hash.new
|
12
|
+
data['total'] = host.hardware.memorySize.bytes.to.megabytes.to_f
|
13
|
+
data['usage'] = host.summary.quickStats.overallMemoryUsage.megabytes.to_f
|
14
|
+
data['percent'] = (data['usage'] / data['total']) * 100
|
15
|
+
data
|
16
|
+
end
|
17
|
+
|
18
|
+
def host_cpu (host)
|
19
|
+
data = Hash.new
|
20
|
+
data['Mhz'] = host.hardware.cpuInfo.hz / 1000 / 1000
|
21
|
+
data['cores'] = host.hardware.cpuInfo.numCpuCores
|
22
|
+
data['totalMhz'] = data['Mhz'] * data['cores']
|
23
|
+
data['usageMhz'] = host.summary.quickStats.overallCpuUsage.to_f
|
24
|
+
data['percent'] = (data['usageMhz'] / data['totalMhz']) * 100
|
25
|
+
data
|
26
|
+
end
|
27
|
+
|
28
|
+
def host_stats (host)
|
29
|
+
data = Hash.new
|
30
|
+
data['memory'] = host_memory(host)
|
31
|
+
data['cpu'] = host_cpu(host)
|
32
|
+
data
|
33
|
+
end
|
34
|
+
|
35
|
+
def cluster_memory (cluster)
|
36
|
+
data = Hash.new
|
37
|
+
data['totalMemory'] = cluster.summary.totalMemory
|
38
|
+
data['effectiveMemory'] = cluster.summary.effectiveMemory
|
39
|
+
data
|
40
|
+
end
|
41
|
+
|
42
|
+
def cluster_cpu (cluster)
|
43
|
+
data = Hash.new
|
44
|
+
data['totalCpu'] = cluster.summary.totalCpu
|
45
|
+
data['numCpuCores'] = cluster.summary.numCpuCores
|
46
|
+
data['numCpuThreads'] = cluster.summary.numCpuThreads
|
47
|
+
data['effectiveCpu'] = cluster.summary.effectiveCpu
|
48
|
+
data
|
49
|
+
end
|
50
|
+
|
51
|
+
def cluster_stats (cluster)
|
52
|
+
data = Hash.new
|
53
|
+
data['cpu'] = cluster_cpu(cluster)
|
54
|
+
data['memory'] = cluster_memory(cluster)
|
55
|
+
data['numVmotions'] = cluster.summary.numVmotions
|
56
|
+
data['numHosts'] = cluster.summary.numHosts
|
57
|
+
data['numEffectiveHosts'] = cluster.summary.numEffectiveHosts
|
58
|
+
data['targetBalance'] = cluster.summary.targetBalance
|
59
|
+
data['currentBalance'] = cluster.summary.currentBalance
|
60
|
+
data
|
61
|
+
end
|
62
|
+
|
63
|
+
def datastore_stats (datastore)
|
64
|
+
data = Hash.new
|
65
|
+
datastore.RefreshDatastore
|
66
|
+
capacity = datastore.summary.capacity
|
67
|
+
freeSpace = datastore.summary.freeSpace
|
68
|
+
uncommitted = datastore.summary.uncommitted
|
69
|
+
data['capacityM'] = ((capacity / 1024) / 1024) if capacity.class != NilClass
|
70
|
+
data['freeSpaceM'] = ((freeSpace / 1024) / 1024) if freeSpace.class != NilClass
|
71
|
+
data['uncommittedM'] = ((uncommitted / 1024) / 1024) if uncommitted.class != NilClass
|
72
|
+
data
|
73
|
+
end
|
74
|
+
|
75
|
+
def network_stats (network)
|
76
|
+
data = Hash.new
|
77
|
+
data
|
78
|
+
end
|
79
|
+
|
80
|
+
def process_datacenter (dc)
|
81
|
+
data = Hash.new
|
82
|
+
data['hypers'] = Hash.new
|
83
|
+
data['clusters'] = Hash.new
|
84
|
+
data['datastores'] = Hash.new
|
85
|
+
# Get the information for host
|
86
|
+
host_list = dc.hostFolder.children.select {|h| h.class == RbVmomi::VIM::ComputeResource }
|
87
|
+
host_list.map {|h|
|
88
|
+
data['hypers'][h.name] = host_stats(h.host.first)
|
89
|
+
}
|
90
|
+
|
91
|
+
# Get the information for each host in a cluster
|
92
|
+
cluster_list = dc.hostFolder.children.select {|h| h.class == RbVmomi::VIM::ClusterComputeResource }
|
93
|
+
cluster_list.map {|c|
|
94
|
+
data['clusters'][c.name] = cluster_stats(c)
|
95
|
+
c.host.map {|h|
|
96
|
+
data['hypers'][h.name] = host_stats(h)
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
# Get informaton about datastore usage
|
101
|
+
datastore_list = dc.datastore
|
102
|
+
datastore_list.map {|d|
|
103
|
+
data['datastores'][d.name] = datastore_stats(d)
|
104
|
+
}
|
105
|
+
|
106
|
+
data['vm_count'] = dc.vmFolder.children.select {|v| v.class == RbVmomi::VIM::VirtualMachine }.size
|
107
|
+
data
|
108
|
+
end
|
109
|
+
|
110
|
+
def process_all_datacenters (datacenterlist,vim)
|
111
|
+
|
112
|
+
data = Hash.new
|
113
|
+
datacenterlist.each do |datacenter|
|
114
|
+
dc = vim.serviceInstance.find_datacenter datacenter
|
115
|
+
data[dc.name] = VSphereMonitoring.process_datacenter(dc)
|
116
|
+
end
|
117
|
+
data
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vspheremonitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Zach Leslie
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yaml
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rbvmomi
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: alchemist
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Parses json from the various node states on puppet dashboard and returns
|
79
|
+
those values in a json blob
|
80
|
+
email: xaque208@gmail.com
|
81
|
+
executables:
|
82
|
+
- vspheremonitor
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- Rakefile
|
87
|
+
- bin/vspheremonitor
|
88
|
+
- lib/vspheremonitoring.rb
|
89
|
+
- etc/vsphere.yaml.sample
|
90
|
+
- README.md
|
91
|
+
homepage: https://github.com/xaque208/vspheremonitor
|
92
|
+
licenses: []
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.8.24
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: A tool to get the highlights from the Puppet Dashboard
|
115
|
+
test_files: []
|