ovirt_metrics 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/lib/models/calendar.rb +4 -0
- data/lib/models/cluster_configuration.rb +4 -0
- data/lib/models/datacenter_configuration.rb +4 -0
- data/lib/models/datacenter_daily_history.rb +4 -0
- data/lib/models/datacenter_hourly_history.rb +4 -0
- data/lib/models/datacenter_samples_history.rb +4 -0
- data/lib/models/datacenter_storage_domain_map.rb +4 -0
- data/lib/models/disks_vm_map.rb +5 -0
- data/lib/models/enum_translator.rb +4 -0
- data/lib/models/history_configuration.rb +4 -0
- data/lib/models/host_configuration.rb +21 -0
- data/lib/models/host_daily_history.rb +4 -0
- data/lib/models/host_hourly_history.rb +4 -0
- data/lib/models/host_interface_configuration.rb +6 -0
- data/lib/models/host_interface_daily_history.rb +4 -0
- data/lib/models/host_interface_hourly_history.rb +4 -0
- data/lib/models/host_interface_samples_history.rb +29 -0
- data/lib/models/host_samples_history.rb +10 -0
- data/lib/models/ovirt_history.rb +18 -0
- data/lib/models/period.rb +4 -0
- data/lib/models/storage_domain_configuration.rb +4 -0
- data/lib/models/storage_domain_daily_history.rb +4 -0
- data/lib/models/storage_domain_hourly_history.rb +4 -0
- data/lib/models/storage_domain_samples_history.rb +4 -0
- data/lib/models/tag_details.rb +4 -0
- data/lib/models/tag_relations_history.rb +4 -0
- data/lib/models/vm_configuration.rb +8 -0
- data/lib/models/vm_daily_history.rb +4 -0
- data/lib/models/vm_disk_configuration.rb +4 -0
- data/lib/models/vm_disk_daily_history.rb +4 -0
- data/lib/models/vm_disk_hourly_history.rb +4 -0
- data/lib/models/vm_disk_samples_history.rb +18 -0
- data/lib/models/vm_disks_usage_daily_history.rb +4 -0
- data/lib/models/vm_disks_usage_hourly_history.rb +4 -0
- data/lib/models/vm_disks_usage_samples_history.rb +4 -0
- data/lib/models/vm_hourly_history.rb +4 -0
- data/lib/models/vm_interface_configuration.rb +6 -0
- data/lib/models/vm_interface_daily_history.rb +4 -0
- data/lib/models/vm_interface_hourly_history.rb +4 -0
- data/lib/models/vm_interface_samples_history.rb +29 -0
- data/lib/models/vm_samples_history.rb +17 -0
- data/lib/ovirt_metrics/constants.rb +131 -0
- data/lib/ovirt_metrics/version.rb +3 -0
- data/lib/ovirt_metrics.rb +149 -0
- data/ovirt_metrics.gemspec +28 -0
- data/spec/models/host_configuration_spec.rb +35 -0
- data/spec/models/host_interface_samples_history_spec.rb +37 -0
- data/spec/models/host_samples_history_spec.rb +51 -0
- data/spec/models/vm_disk_samples_history_spec.rb +46 -0
- data/spec/models/vm_interface_samples_history_spec.rb +37 -0
- data/spec/models/vm_samples_history_spec.rb +44 -0
- data/spec/ovirt_metrics_spec.rb +6 -0
- data/spec/schemas/schema_rhev30.rb +655 -0
- data/spec/schemas/schema_rhev31.rb +679 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/active_record.rb +42 -0
- data/travis.yml +9 -0
- metadata +225 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
require "ovirt_metrics/version"
|
2
|
+
require "ovirt_metrics/constants"
|
3
|
+
|
4
|
+
$:.push File.expand_path(File.dirname(__FILE__))
|
5
|
+
require 'models/ovirt_history'
|
6
|
+
Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "models", "*.rb"))) { |f| require "models/#{File.basename(f, ".*")}" }
|
7
|
+
|
8
|
+
module OvirtMetrics
|
9
|
+
DEFAULT_HISTORY_DATABASE_NAME = "ovirt_engine_history".freeze
|
10
|
+
|
11
|
+
def self.establish_connection(opts)
|
12
|
+
self.connect(opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.connect(opts)
|
16
|
+
opts ||= {}
|
17
|
+
opts[:port] ||= 5432
|
18
|
+
opts[:database] ||= DEFAULT_HISTORY_DATABASE_NAME
|
19
|
+
opts[:adapter] = 'postgresql'
|
20
|
+
|
21
|
+
# Don't allow accidental connections to localhost. A blank host will
|
22
|
+
# connect to localhost, so don't allow that at all.
|
23
|
+
host = opts[:host].to_s.strip
|
24
|
+
raise ArgumentError, "host cannot be blank" if host.empty?
|
25
|
+
raise ArgumentError, "host cannot be set to localhost" if ["localhost", "localhost.localdomain", "127.0.0.1", "0.0.0.0"].include?(host)
|
26
|
+
|
27
|
+
OvirtHistory.establish_connection(opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.connected?
|
31
|
+
OvirtHistory.connection.active?
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.disconnect
|
35
|
+
OvirtHistory.connection.disconnect!
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.vm_realtime(vm_id, start_time = nil, end_time = nil)
|
39
|
+
metrics = query_vm_realtime_metrics(vm_id, start_time, end_time)
|
40
|
+
disk_metrics = query_vm_disk_realtime_metrics(vm_id, start_time, end_time)
|
41
|
+
nic_metrics = query_vm_nic_realtime_metrics(vm_id, start_time, end_time)
|
42
|
+
hashes = vm_realtime_metrics_to_hashes(metrics, disk_metrics, nic_metrics)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.host_realtime(host_id, start_time = nil, end_time = nil)
|
46
|
+
metrics = query_host_realtime_metrics(host_id, start_time, end_time).all
|
47
|
+
nic_metrics = query_host_nic_realtime_metrics(host_id, start_time, end_time)
|
48
|
+
hashes = host_realtime_metrics_to_hashes(metrics, nic_metrics)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.query_host_realtime_metrics(host_id, start_time = nil, end_time = nil)
|
54
|
+
query = HostSamplesHistory.where(:host_id => host_id).includes(:host_configuration)
|
55
|
+
query = query.where(:history_datetime => (start_time..(end_time || Time.now.utc))) unless start_time.nil?
|
56
|
+
query
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.query_host_nic_realtime_metrics(host_id, start_time = nil, end_time = nil)
|
60
|
+
nic_ids = HostInterfaceConfiguration.where(:host_id => host_id).collect(&:host_interface_id)
|
61
|
+
query = HostInterfaceSamplesHistory.where(:host_interface_id => nic_ids)
|
62
|
+
query = query.where(:history_datetime => (start_time..(end_time || Time.now.utc))) unless start_time.nil?
|
63
|
+
query
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.host_realtime_metrics_to_hashes(metrics, nic_metrics)
|
67
|
+
counters_by_id = {}
|
68
|
+
counter_values_by_id_and_ts = {}
|
69
|
+
|
70
|
+
nic_metrics = nic_metrics.group_by { |m| m.history_datetime }
|
71
|
+
|
72
|
+
metrics.each do |metric|
|
73
|
+
options = {
|
74
|
+
:metric => metric,
|
75
|
+
:nic => nic_metrics[metric.history_datetime]
|
76
|
+
}
|
77
|
+
|
78
|
+
href = "/api/hosts/#{metric.host_id}"
|
79
|
+
counters_by_id[href] ||= {}
|
80
|
+
values = {}
|
81
|
+
|
82
|
+
HOST_COLUMN_DEFINITIONS.each do |evm_col, info|
|
83
|
+
counters_by_id[href][info[:ovirt_key]] ||= info[:counter]
|
84
|
+
values[info[:ovirt_key]] = info[:ovirt_method].call(options)
|
85
|
+
end
|
86
|
+
|
87
|
+
# For (temporary) symmetry with VIM API having 20-second intervals
|
88
|
+
counter_values_by_id_and_ts[href] ||= {}
|
89
|
+
[0, 20, 40].each do |t|
|
90
|
+
counter_values_by_id_and_ts[href][(metric.history_datetime + t).utc.iso8601] = values
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
return counters_by_id, counter_values_by_id_and_ts
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.query_vm_realtime_metrics(vm_id, start_time = nil, end_time = nil)
|
98
|
+
query = VmSamplesHistory.where(:vm_id => vm_id).includes(:host_configuration)
|
99
|
+
query = query.where(:history_datetime => (start_time..(end_time || Time.now.utc))) unless start_time.nil?
|
100
|
+
query
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.query_vm_disk_realtime_metrics(vm_id, start_time = nil, end_time = nil)
|
104
|
+
disk_ids = DisksVmMap.where(:vm_id => vm_id).collect(&:vm_disk_id)
|
105
|
+
query = VmDiskSamplesHistory.where(:vm_disk_id => disk_ids)
|
106
|
+
query = query.where(:history_datetime => (start_time..(end_time || Time.now.utc))) unless start_time.nil?
|
107
|
+
query
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.query_vm_nic_realtime_metrics(vm_id, start_time = nil, end_time = nil)
|
111
|
+
nic_ids = VmInterfaceConfiguration.where(:vm_id => vm_id).collect(&:vm_interface_id)
|
112
|
+
query = VmInterfaceSamplesHistory.where(:vm_interface_id => nic_ids)
|
113
|
+
query = query.where(:history_datetime => (start_time..(end_time || Time.now.utc))) unless start_time.nil?
|
114
|
+
query
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.vm_realtime_metrics_to_hashes(metrics, disk_metrics, nic_metrics)
|
118
|
+
counters_by_id = {}
|
119
|
+
counter_values_by_id_and_ts = {}
|
120
|
+
|
121
|
+
disk_metrics = disk_metrics.group_by { |m| m.history_datetime }
|
122
|
+
nic_metrics = nic_metrics.group_by { |m| m.history_datetime }
|
123
|
+
|
124
|
+
metrics.each do |metric|
|
125
|
+
options = {
|
126
|
+
:metric => metric,
|
127
|
+
:disk => disk_metrics[metric.history_datetime],
|
128
|
+
:nic => nic_metrics[metric.history_datetime]
|
129
|
+
}
|
130
|
+
|
131
|
+
href = "/api/vms/#{metric.vm_id}"
|
132
|
+
counters_by_id[href] ||= {}
|
133
|
+
values = {}
|
134
|
+
|
135
|
+
VM_COLUMN_DEFINITIONS.each do |evm_col, info|
|
136
|
+
counters_by_id[href][info[:ovirt_key]] ||= info[:counter]
|
137
|
+
values[info[:ovirt_key]] = info[:ovirt_method].call(options)
|
138
|
+
end
|
139
|
+
|
140
|
+
# For (temporary) symmetry with VIM API having 20-second intervals
|
141
|
+
counter_values_by_id_and_ts[href] ||= {}
|
142
|
+
[0, 20, 40].each do |t|
|
143
|
+
counter_values_by_id_and_ts[href][(metric.history_datetime + t).utc.iso8601] = values
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
return counters_by_id, counter_values_by_id_and_ts
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ovirt_metrics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ovirt_metrics"
|
8
|
+
spec.version = OvirtMetrics::VERSION
|
9
|
+
spec.authors = ["Oleg Barenboim", "Jason Frey"]
|
10
|
+
spec.email = ["chessbyte@gmail.com", "fryguy9@gmail.com"]
|
11
|
+
spec.description = %q{OvirtMetrics is an ActiveRecord-based gem for reading the oVirt History database.}
|
12
|
+
spec.summary = %q{OvirtMetrics is an ActiveRecord-based gem for reading the oVirt History database.}
|
13
|
+
spec.homepage = "http://github.com/ManageIQ/ovirt_metrics"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "sqlite3"
|
25
|
+
spec.add_development_dependency "coveralls"
|
26
|
+
|
27
|
+
spec.add_dependency "activerecord", "~> 3.2.0"
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w{.. spec_helper}))
|
2
|
+
|
3
|
+
require 'ovirt_metrics'
|
4
|
+
|
5
|
+
describe OvirtMetrics::HostConfiguration do
|
6
|
+
shared_examples_for "HostConfiguration" do
|
7
|
+
context "#speed_in_mhz" do
|
8
|
+
it "when cpu_model is nil" do
|
9
|
+
described_class.new(:cpu_model => nil).speed_in_mhz.should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "when cpu_model is in GHz" do
|
13
|
+
described_class.new(:cpu_model => "Intel(R) Xeon(R) CPU E5506 @ 2.00GHz").speed_in_mhz.should == 2048.0
|
14
|
+
end
|
15
|
+
|
16
|
+
it "when cpu_model is in MHz" do
|
17
|
+
described_class.new(:cpu_model => "Intel(R) Xeon(R) CPU E5506 @ 2.00MHz").speed_in_mhz.should == 2.0
|
18
|
+
end
|
19
|
+
|
20
|
+
it "when cpu_model is some other string" do
|
21
|
+
described_class.new(:cpu_model => "XXX").speed_in_mhz.should be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "RHEV 3.0" do
|
27
|
+
before(:each) { load_rhev_30 }
|
28
|
+
it_should_behave_like "HostConfiguration"
|
29
|
+
end
|
30
|
+
|
31
|
+
context "RHEV 3.1" do
|
32
|
+
before(:each) { load_rhev_31 }
|
33
|
+
it_should_behave_like "HostConfiguration"
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w{.. spec_helper}))
|
2
|
+
|
3
|
+
require 'ovirt_metrics'
|
4
|
+
|
5
|
+
describe OvirtMetrics::HostInterfaceSamplesHistory do
|
6
|
+
shared_examples_for "HostInterfaceSamplesHistory" do
|
7
|
+
context ".net_usage_rate_average_in_kilobytes_per_second" do
|
8
|
+
it "when nic_metrics array is empty" do
|
9
|
+
described_class.net_usage_rate_average_in_kilobytes_per_second([]).should == 0.0
|
10
|
+
end
|
11
|
+
|
12
|
+
it "when nic_metrics array has one element with 90% receiving and 10% transmitting" do
|
13
|
+
nic_metric = double("nic_metric")
|
14
|
+
nic_metric.stub(:receive_rate_percent => 90, :transmit_rate_percent => 10)
|
15
|
+
described_class.net_usage_rate_average_in_kilobytes_per_second([nic_metric]).should == (described_class::GIGABYTE_PER_SECOND / 2) / 1024
|
16
|
+
end
|
17
|
+
|
18
|
+
it "when nic_metrics array has two elements with 90% receiving and 10% transmitting each" do
|
19
|
+
nic_metric1 = double("nic_metric")
|
20
|
+
nic_metric1.stub(:receive_rate_percent => 90, :transmit_rate_percent => 10)
|
21
|
+
nic_metric2 = double("nic_metric")
|
22
|
+
nic_metric2.stub(:receive_rate_percent => 90, :transmit_rate_percent => 10)
|
23
|
+
described_class.net_usage_rate_average_in_kilobytes_per_second([nic_metric1, nic_metric2]).should == (described_class::GIGABYTE_PER_SECOND / 2) / 1024
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "RHEV 3.0" do
|
29
|
+
before(:each) { load_rhev_30 }
|
30
|
+
it_should_behave_like "HostInterfaceSamplesHistory"
|
31
|
+
end
|
32
|
+
|
33
|
+
context "RHEV 3.1" do
|
34
|
+
before(:each) { load_rhev_31 }
|
35
|
+
it_should_behave_like "HostInterfaceSamplesHistory"
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w{.. spec_helper}))
|
2
|
+
|
3
|
+
require 'ovirt_metrics'
|
4
|
+
|
5
|
+
describe OvirtMetrics::HostSamplesHistory do
|
6
|
+
shared_examples_for "HostSamplesHistory" do
|
7
|
+
context "#cpu_usagemhz_rate_average" do
|
8
|
+
before(:each) { @host_configuration = OvirtMetrics::HostConfiguration.new }
|
9
|
+
context "when host_configuration exists" do
|
10
|
+
it "and speed_in_mhz and number_of_cores is nil" do
|
11
|
+
host_history = described_class.new(:host_configuration => @host_configuration)
|
12
|
+
host_history.cpu_usagemhz_rate_average.should == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it "and speed_in_mhz is nil and number_of_cores is numeric" do
|
16
|
+
host_history = described_class.new(:host_configuration => @host_configuration)
|
17
|
+
@host_configuration.stub(:number_of_cores => 1)
|
18
|
+
host_history.cpu_usagemhz_rate_average.should == 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it "and speed_in_mhz is numeric and number_of_cores is nil" do
|
22
|
+
host_history = described_class.new(:host_configuration => @host_configuration)
|
23
|
+
@host_configuration.stub(:speed_in_mhz => 2048.0)
|
24
|
+
host_history.cpu_usagemhz_rate_average.should == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it "and speed_in_mhz is numeric and number_of_cores is numeric" do
|
28
|
+
host_configuration = OvirtMetrics::HostConfiguration.new
|
29
|
+
@host_configuration.stub(:speed_in_mhz => 2048.0)
|
30
|
+
@host_configuration.stub(:number_of_cores => 2)
|
31
|
+
|
32
|
+
host_history = described_class.new(
|
33
|
+
:cpu_usage_percent => 50,
|
34
|
+
:host_configuration => @host_configuration
|
35
|
+
)
|
36
|
+
host_history.cpu_usagemhz_rate_average.should == 2048.0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "RHEV 3.0" do
|
43
|
+
before(:each) { load_rhev_30 }
|
44
|
+
it_should_behave_like "HostSamplesHistory"
|
45
|
+
end
|
46
|
+
|
47
|
+
context "RHEV 3.1" do
|
48
|
+
before(:each) { load_rhev_31 }
|
49
|
+
it_should_behave_like "HostSamplesHistory"
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w{.. spec_helper}))
|
2
|
+
|
3
|
+
require 'ovirt_metrics'
|
4
|
+
|
5
|
+
describe OvirtMetrics::VmDiskSamplesHistory do
|
6
|
+
KILOBYTE = 1024
|
7
|
+
MEGABYTE = KILOBYTE * 1024
|
8
|
+
|
9
|
+
shared_examples_for "VmDiskSamplesHistory" do
|
10
|
+
context ".disk_usage_rate_average_in_kilobytes_per_second" do
|
11
|
+
it "when disk_metrics array is empty" do
|
12
|
+
described_class.disk_usage_rate_average_in_kilobytes_per_second([]).should == 0.0
|
13
|
+
end
|
14
|
+
|
15
|
+
it "when disk_metrics array has one element" do
|
16
|
+
disk_metric = double("disk_metric")
|
17
|
+
disk_metric.stub(:read_rate_bytes_per_second => 2.0 * MEGABYTE, :write_rate_bytes_per_second => 1.0 * MEGABYTE)
|
18
|
+
expected_result = (disk_metric.read_rate_bytes_per_second + disk_metric.write_rate_bytes_per_second) / KILOBYTE
|
19
|
+
described_class.disk_usage_rate_average_in_kilobytes_per_second([disk_metric]).should == expected_result
|
20
|
+
end
|
21
|
+
|
22
|
+
it "when disk_metrics array has two elements" do
|
23
|
+
disk_metric1 = double("disk_metric")
|
24
|
+
disk_metric1.stub(:read_rate_bytes_per_second => 2.0 * MEGABYTE, :write_rate_bytes_per_second => 1.0 * MEGABYTE)
|
25
|
+
|
26
|
+
disk_metric2 = double("disk_metric")
|
27
|
+
disk_metric2.stub(:read_rate_bytes_per_second => 2.0 * MEGABYTE, :write_rate_bytes_per_second => 5.0 * MEGABYTE)
|
28
|
+
|
29
|
+
sum_m1 = disk_metric1.read_rate_bytes_per_second + disk_metric1.write_rate_bytes_per_second
|
30
|
+
sum_m2 = disk_metric2.read_rate_bytes_per_second + disk_metric2.write_rate_bytes_per_second
|
31
|
+
expected_result = (sum_m1 + sum_m2) / KILOBYTE / 2
|
32
|
+
described_class.disk_usage_rate_average_in_kilobytes_per_second([disk_metric1, disk_metric2]).should == expected_result
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "RHEV 3.0" do
|
38
|
+
before(:each) { load_rhev_30 }
|
39
|
+
it_should_behave_like "VmDiskSamplesHistory"
|
40
|
+
end
|
41
|
+
|
42
|
+
context "RHEV 3.1" do
|
43
|
+
before(:each) { load_rhev_31 }
|
44
|
+
it_should_behave_like "VmDiskSamplesHistory"
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w{.. spec_helper}))
|
2
|
+
|
3
|
+
require 'ovirt_metrics'
|
4
|
+
|
5
|
+
describe OvirtMetrics::VmInterfaceSamplesHistory do
|
6
|
+
shared_examples_for "VmInterfaceSamplesHistory" do
|
7
|
+
context ".net_usage_rate_average_in_kilobytes_per_second" do
|
8
|
+
it "when nic_metrics array is empty" do
|
9
|
+
described_class.net_usage_rate_average_in_kilobytes_per_second([]).should == 0.0
|
10
|
+
end
|
11
|
+
|
12
|
+
it "when nic_metrics array has one element with 90% receiving and 10% transmitting" do
|
13
|
+
nic_metric = double("nic_metric")
|
14
|
+
nic_metric.stub(:receive_rate_percent => 90, :transmit_rate_percent => 10)
|
15
|
+
described_class.net_usage_rate_average_in_kilobytes_per_second([nic_metric]).should == (described_class::GIGABYTE_PER_SECOND / 2) / 1024
|
16
|
+
end
|
17
|
+
|
18
|
+
it "when nic_metrics array has two elements with 90% receiving and 10% transmitting each" do
|
19
|
+
nic_metric1 = double("nic_metric")
|
20
|
+
nic_metric1.stub(:receive_rate_percent => 90, :transmit_rate_percent => 10)
|
21
|
+
nic_metric2 = double("nic_metric")
|
22
|
+
nic_metric2.stub(:receive_rate_percent => 90, :transmit_rate_percent => 10)
|
23
|
+
described_class.net_usage_rate_average_in_kilobytes_per_second([nic_metric1, nic_metric2]).should == (described_class::GIGABYTE_PER_SECOND / 2) / 1024
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "RHEV 3.0" do
|
29
|
+
before(:each) { load_rhev_30 }
|
30
|
+
it_should_behave_like "VmInterfaceSamplesHistory"
|
31
|
+
end
|
32
|
+
|
33
|
+
context "RHEV 3.1" do
|
34
|
+
before(:each) { load_rhev_31 }
|
35
|
+
it_should_behave_like "VmInterfaceSamplesHistory"
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w{.. spec_helper}))
|
2
|
+
|
3
|
+
require 'ovirt_metrics'
|
4
|
+
|
5
|
+
describe OvirtMetrics::VmSamplesHistory do
|
6
|
+
shared_examples_for "VmSamplesHistory" do
|
7
|
+
context "#cpu_usagemhz_rate_average" do
|
8
|
+
it "when host_configuration is nil" do
|
9
|
+
vm_history = described_class.new
|
10
|
+
vm_history.stub(:host_configuration => nil)
|
11
|
+
|
12
|
+
vm_history.cpu_usagemhz_rate_average.should == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when host_configuration exists" do
|
16
|
+
it "and speed_in_mhz is nil" do
|
17
|
+
vm_history = described_class.new(:host_configuration => OvirtMetrics::HostConfiguration.new)
|
18
|
+
vm_history.cpu_usagemhz_rate_average.should == 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it "and speed_in_mhz is not nil" do
|
22
|
+
host_configuration = OvirtMetrics::HostConfiguration.new
|
23
|
+
host_configuration.stub(:speed_in_mhz => 2048.0)
|
24
|
+
|
25
|
+
vm_history = described_class.new(
|
26
|
+
:cpu_usage_percent => 50,
|
27
|
+
:host_configuration => host_configuration
|
28
|
+
)
|
29
|
+
vm_history.cpu_usagemhz_rate_average.should == 1024.0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "RHEV 3.0" do
|
36
|
+
before(:each) { load_rhev_30 }
|
37
|
+
it_should_behave_like "VmSamplesHistory"
|
38
|
+
end
|
39
|
+
|
40
|
+
context "RHEV 3.1" do
|
41
|
+
before(:each) { load_rhev_31 }
|
42
|
+
it_should_behave_like "VmSamplesHistory"
|
43
|
+
end
|
44
|
+
end
|