ovirt_metrics 1.0.0 → 1.0.1

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.
@@ -1,29 +1,7 @@
1
1
  module OvirtMetrics
2
2
  class HostInterfaceSamplesHistory < OvirtHistory
3
- belongs_to :host_interface_configuration, :foreign_key => :host_interface_configuration_version
4
-
5
- KILO = 1024
6
- MEGA = 1024 * KILO
7
- GIGA = 1024 * MEGA
8
- GIGABIT_PER_SECOND = GIGA
9
- GIGABYTE_PER_SECOND = GIGABIT_PER_SECOND / 8
10
-
11
- def self.net_usage_rate_average_in_kilobytes_per_second(nic_metrics)
12
- count = 0
13
- sum = 0
14
- nic_metrics ||= []
15
- nic_metrics.each do |n|
16
- sum += (n.receive_rate_percent.to_f + n.transmit_rate_percent.to_f) / 2
17
- count += 1
18
- end
19
-
20
- return 0.0 if count == 0
21
-
22
- percentage = sum / 100.0
23
- bytes_per_second = percentage * GIGABYTE_PER_SECOND
24
-
25
- (bytes_per_second / count) / 1024
26
- end
3
+ extend NicMetrics
27
4
 
5
+ belongs_to :host_interface_configuration, :foreign_key => :host_interface_configuration_version
28
6
  end
29
7
  end
@@ -3,6 +3,7 @@ module OvirtMetrics
3
3
  belongs_to :host_configuration, :foreign_key => :host_configuration_version
4
4
 
5
5
  def cpu_usagemhz_rate_average
6
+ return 0.0 if self.host_configuration.nil?
6
7
  speed_of_host = self.host_configuration.speed_in_mhz.to_f * self.host_configuration.number_of_cores.to_i
7
8
  return (speed_of_host * (self.cpu_usage_percent.to_f / 100.0))
8
9
  end
@@ -1,29 +1,7 @@
1
1
  module OvirtMetrics
2
2
  class VmInterfaceSamplesHistory < OvirtHistory
3
- belongs_to :vm_interface_configuration, :foreign_key => :vm_interface_configuration_version
4
-
5
- KILO = 1024
6
- MEGA = 1024 * KILO
7
- GIGA = 1024 * MEGA
8
- GIGABIT_PER_SECOND = GIGA
9
- GIGABYTE_PER_SECOND = GIGABIT_PER_SECOND / 8
10
-
11
- def self.net_usage_rate_average_in_kilobytes_per_second(nic_metrics)
12
- count = 0
13
- sum = 0
14
- nic_metrics ||= []
15
- nic_metrics.each do |n|
16
- sum += (n.receive_rate_percent.to_f + n.transmit_rate_percent.to_f) / 2
17
- count += 1
18
- end
19
-
20
- return 0.0 if count == 0
21
-
22
- percentage = sum / 100.0
23
- bytes_per_second = percentage * GIGABYTE_PER_SECOND
24
-
25
- (bytes_per_second / count) / 1024
26
- end
3
+ extend NicMetrics
27
4
 
5
+ belongs_to :vm_interface_configuration, :foreign_key => :vm_interface_configuration_version
28
6
  end
29
7
  end
@@ -1,12 +1,14 @@
1
1
  require "ovirt_metrics/version"
2
- require "ovirt_metrics/constants"
2
+ require "ovirt_metrics/column_definitions"
3
+ require "ovirt_metrics/nic_metrics"
3
4
 
4
5
  $:.push File.expand_path(File.dirname(__FILE__))
5
6
  require 'models/ovirt_history'
6
7
  Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), "models", "*.rb"))) { |f| require "models/#{File.basename(f, ".*")}" }
7
8
 
8
9
  module OvirtMetrics
9
- DEFAULT_HISTORY_DATABASE_NAME = "ovirt_engine_history".freeze
10
+ DEFAULT_HISTORY_DATABASE_NAME = "ovirt_engine_history".freeze
11
+ DEFAULT_HISTORY_DATABASE_NAME_3_0 = "rhevm_history".freeze
10
12
 
11
13
  def self.establish_connection(opts)
12
14
  self.connect(opts)
@@ -0,0 +1,30 @@
1
+ module OvirtMetrics
2
+ module NicMetrics
3
+ KILO = 1024
4
+ MEGA = 1024 * KILO
5
+ GIGA = 1024 * MEGA
6
+ GIGABIT_PER_SECOND = GIGA
7
+ GIGABYTE_PER_SECOND = GIGABIT_PER_SECOND / 8
8
+
9
+ def self.net_usage_rate_average_in_kilobytes_per_second(nic_metrics)
10
+ count = 0
11
+ sum = 0
12
+ nic_metrics ||= []
13
+ nic_metrics.each do |n|
14
+ sum += (n.receive_rate_percent.to_f + n.transmit_rate_percent.to_f) / 2
15
+ count += 1
16
+ end
17
+
18
+ return 0.0 if count == 0
19
+
20
+ percentage = sum / 100.0
21
+ bytes_per_second = percentage * GIGABYTE_PER_SECOND
22
+
23
+ (bytes_per_second / count) / 1024
24
+ end
25
+
26
+ def net_usage_rate_average_in_kilobytes_per_second(nic_metrics)
27
+ NicMetrics.net_usage_rate_average_in_kilobytes_per_second(nic_metrics)
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module OvirtMetrics
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -5,8 +5,14 @@ require 'ovirt_metrics'
5
5
  describe OvirtMetrics::HostSamplesHistory do
6
6
  shared_examples_for "HostSamplesHistory" do
7
7
  context "#cpu_usagemhz_rate_average" do
8
- before(:each) { @host_configuration = OvirtMetrics::HostConfiguration.new }
8
+
9
+ it "when host_configuration is nil" do
10
+ host_history = described_class.new(:host_configuration => nil)
11
+ host_history.cpu_usagemhz_rate_average.should == 0
12
+ end
13
+
9
14
  context "when host_configuration exists" do
15
+ before(:each) { @host_configuration = OvirtMetrics::HostConfiguration.new }
10
16
  it "and speed_in_mhz and number_of_cores is nil" do
11
17
  host_history = described_class.new(:host_configuration => @host_configuration)
12
18
  host_history.cpu_usagemhz_rate_average.should == 0
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
+
3
+ require 'ovirt_metrics'
4
+
5
+ describe OvirtMetrics::NicMetrics do
6
+ context ".net_usage_rate_average_in_kilobytes_per_second" do
7
+ it "when nic_metrics array is empty" do
8
+ described_class.net_usage_rate_average_in_kilobytes_per_second([]).should == 0.0
9
+ end
10
+
11
+ it "when nic_metrics array has one element" do
12
+ nic_metric = double("nic_metric")
13
+ nic_metric.stub(:receive_rate_percent => 90, :transmit_rate_percent => 10)
14
+ expected = (OvirtMetrics::NicMetrics::GIGABYTE_PER_SECOND / 2) / 1024
15
+ described_class.net_usage_rate_average_in_kilobytes_per_second([nic_metric]).should == expected
16
+ end
17
+
18
+ it "when nic_metrics array has multiple elements" 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
+ expected = (OvirtMetrics::NicMetrics::GIGABYTE_PER_SECOND / 2) / 1024
24
+ described_class.net_usage_rate_average_in_kilobytes_per_second([nic_metric1, nic_metric2]).should == expected
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovirt_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-18 00:00:00.000000000 Z
13
+ date: 2013-04-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -165,15 +165,15 @@ files:
165
165
  - lib/models/vm_interface_samples_history.rb
166
166
  - lib/models/vm_samples_history.rb
167
167
  - lib/ovirt_metrics.rb
168
- - lib/ovirt_metrics/constants.rb
168
+ - lib/ovirt_metrics/column_definitions.rb
169
+ - lib/ovirt_metrics/nic_metrics.rb
169
170
  - lib/ovirt_metrics/version.rb
170
171
  - ovirt_metrics.gemspec
171
172
  - spec/models/host_configuration_spec.rb
172
- - spec/models/host_interface_samples_history_spec.rb
173
173
  - spec/models/host_samples_history_spec.rb
174
174
  - spec/models/vm_disk_samples_history_spec.rb
175
- - spec/models/vm_interface_samples_history_spec.rb
176
175
  - spec/models/vm_samples_history_spec.rb
176
+ - spec/nic_metrics_spec.rb
177
177
  - spec/ovirt_metrics_spec.rb
178
178
  - spec/schemas/schema_rhev30.rb
179
179
  - spec/schemas/schema_rhev31.rb
@@ -195,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: -2869768854334440275
198
+ hash: -568016211607175379
199
199
  required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  none: false
201
201
  requirements:
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  version: '0'
205
205
  segments:
206
206
  - 0
207
- hash: -2869768854334440275
207
+ hash: -568016211607175379
208
208
  requirements: []
209
209
  rubyforge_project:
210
210
  rubygems_version: 1.8.24
@@ -213,11 +213,10 @@ specification_version: 3
213
213
  summary: OvirtMetrics is an ActiveRecord-based gem for reading the oVirt History database.
214
214
  test_files:
215
215
  - spec/models/host_configuration_spec.rb
216
- - spec/models/host_interface_samples_history_spec.rb
217
216
  - spec/models/host_samples_history_spec.rb
218
217
  - spec/models/vm_disk_samples_history_spec.rb
219
- - spec/models/vm_interface_samples_history_spec.rb
220
218
  - spec/models/vm_samples_history_spec.rb
219
+ - spec/nic_metrics_spec.rb
221
220
  - spec/ovirt_metrics_spec.rb
222
221
  - spec/schemas/schema_rhev30.rb
223
222
  - spec/schemas/schema_rhev31.rb
@@ -1,37 +0,0 @@
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
@@ -1,37 +0,0 @@
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