ovirt_metrics 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Red Hat, Inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# OvirtMetrics
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/ManageIQ/ovirt_metrics.png?branch=master)](https://travis-ci.org/ManageIQ/ovirt_metrics)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/ManageIQ/ovirt_metrics.png)](https://codeclimate.com/github/ManageIQ/ovirt_metrics)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/ManageIQ/ovirt_metrics/badge.png?branch=master)](https://coveralls.io/r/ManageIQ/ovirt_metrics)
|
6
|
+
|
7
|
+
OvirtMetrics is an ActiveRecord-based gem for reading the oVirt History database.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'ovirt_metrics'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ovirt_metrics
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module OvirtMetrics
|
2
|
+
class HostConfiguration < OvirtHistory
|
3
|
+
has_many :host_interface_configurations, :foreign_key => :host_configuration_version
|
4
|
+
|
5
|
+
belongs_to :cluster_configuration, :foreign_key => :cluster_configuration_version
|
6
|
+
|
7
|
+
GHZ_REGEX = /.*\@\s*(\d+\.\d+)GHz/
|
8
|
+
MHZ_REGEX = /.*\@\s*(\d+\.\d+)MHz/
|
9
|
+
def speed_in_mhz
|
10
|
+
if self.cpu_model.respond_to?(:match)
|
11
|
+
match = self.cpu_model.match(GHZ_REGEX)
|
12
|
+
return (match[1].to_f * 1024) if match
|
13
|
+
|
14
|
+
match = self.cpu_model.match(MHZ_REGEX)
|
15
|
+
return match[1].to_f if match
|
16
|
+
end
|
17
|
+
|
18
|
+
return nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module OvirtMetrics
|
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
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module OvirtMetrics
|
2
|
+
class HostSamplesHistory < OvirtHistory
|
3
|
+
belongs_to :host_configuration, :foreign_key => :host_configuration_version
|
4
|
+
|
5
|
+
def cpu_usagemhz_rate_average
|
6
|
+
speed_of_host = self.host_configuration.speed_in_mhz.to_f * self.host_configuration.number_of_cores.to_i
|
7
|
+
return (speed_of_host * (self.cpu_usage_percent.to_f / 100.0))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module OvirtMetrics
|
4
|
+
class OvirtHistory < ActiveRecord::Base
|
5
|
+
# HACK: The following line is needed so that ActiveRecord 3.2.8 does not try
|
6
|
+
# to dynamically define attribute methods for the OvirtHistory class
|
7
|
+
# itself. This class does not have a backing table, and is only needed to
|
8
|
+
# allow a shared connection for all subclasses. If not set, you get the
|
9
|
+
# error "PGError: ERROR: relation "rhevm_histories" does not exist"
|
10
|
+
@attribute_methods_generated = true
|
11
|
+
|
12
|
+
def self.inherited(other)
|
13
|
+
super
|
14
|
+
other.primary_key = :history_id
|
15
|
+
other.table_name = other.name.split('::').last.underscore
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module OvirtMetrics
|
2
|
+
class VmConfiguration < OvirtHistory
|
3
|
+
belongs_to :cluster_configuration, :foreign_key => :cluster_configuration_version
|
4
|
+
belongs_to :host_configuration, :foreign_key => :default_host_configuration_version
|
5
|
+
|
6
|
+
has_many :vm_interface_configurations, :foreign_key => :vm_configuration_version
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module OvirtMetrics
|
2
|
+
class VmDiskSamplesHistory < OvirtHistory
|
3
|
+
belongs_to :vm_disk_configuration, :foreign_key => :vm_disk_configuration_version
|
4
|
+
|
5
|
+
def self.disk_usage_rate_average_in_kilobytes_per_second(disk_metrics)
|
6
|
+
count = 0
|
7
|
+
sum = 0
|
8
|
+
disk_metrics ||= []
|
9
|
+
disk_metrics.each do |d|
|
10
|
+
sum += d.read_rate_bytes_per_second.to_f + d.write_rate_bytes_per_second.to_f
|
11
|
+
count += 1
|
12
|
+
end
|
13
|
+
|
14
|
+
return 0.0 if count == 0
|
15
|
+
(sum / count) / 1024
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module OvirtMetrics
|
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
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module OvirtMetrics
|
2
|
+
class VmSamplesHistory < OvirtHistory
|
3
|
+
belongs_to :host_configuration, :foreign_key => :current_host_configuration_version
|
4
|
+
belongs_to :vm_configuration, :foreign_key => :vm_configuration_version
|
5
|
+
|
6
|
+
def cpu_usagemhz_rate_average
|
7
|
+
speed_of_host = self.host_configuration.try(:speed_in_mhz).to_f
|
8
|
+
|
9
|
+
# TODO: Research if self.host_configuration.speed_in_mhz is aggregate or per core/socket
|
10
|
+
# enumerator = self.vm_configuration.cpu_per_socket * self.vm_configuration.number_of_sockets
|
11
|
+
# vm_allocation = enumerator.to_f / self.host_configuration.number_of_cores
|
12
|
+
# speed_of_vm = vm_allocation * self.host_configuration.speed_in_mhz
|
13
|
+
|
14
|
+
speed_of_host * (self.cpu_usage_percent.to_f / 100.0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module OvirtMetrics
|
2
|
+
VM_COLUMN_DEFINITIONS = {
|
3
|
+
"cpu_usage_rate_average" => {
|
4
|
+
:ovirt_key => :cpu_usage_rate_average,
|
5
|
+
:ovirt_method => lambda { |metrics| metrics[:metric].cpu_usage_percent.to_f },
|
6
|
+
:counter => {
|
7
|
+
:counter_key => "cpu_usage_rate_average",
|
8
|
+
:instance => "",
|
9
|
+
:capture_interval => "20",
|
10
|
+
:precision => 1,
|
11
|
+
:rollup => "average",
|
12
|
+
:unit_key => "percent",
|
13
|
+
:capture_interval_name => "realtime"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
|
17
|
+
"cpu_usagemhz_rate_average" => {
|
18
|
+
:ovirt_key => :cpu_usagemhz_rate_average,
|
19
|
+
:ovirt_method => lambda { |metrics| metrics[:metric].cpu_usagemhz_rate_average },
|
20
|
+
:counter => {
|
21
|
+
:counter_key => "cpu_usagemhz_rate_average",
|
22
|
+
:instance => "",
|
23
|
+
:capture_interval => "20",
|
24
|
+
:precision => 2,
|
25
|
+
:rollup => "average",
|
26
|
+
:unit_key => "megahertz",
|
27
|
+
:capture_interval_name => "realtime"
|
28
|
+
}
|
29
|
+
},
|
30
|
+
|
31
|
+
"mem_usage_absolute_average" => {
|
32
|
+
:ovirt_key => :mem_usage_absolute_average,
|
33
|
+
:ovirt_method => lambda { |metrics| metrics[:metric].memory_usage_percent.to_f },
|
34
|
+
:counter => {
|
35
|
+
:counter_key => "mem_usage_absolute_average",
|
36
|
+
:instance => "",
|
37
|
+
:capture_interval => "20",
|
38
|
+
:precision => 1,
|
39
|
+
:rollup => "average",
|
40
|
+
:unit_key => "percent",
|
41
|
+
:capture_interval_name => "realtime"
|
42
|
+
}
|
43
|
+
},
|
44
|
+
|
45
|
+
"disk_usage_rate_average" => {
|
46
|
+
:ovirt_key => :disk_usage_rate_average,
|
47
|
+
:ovirt_method => lambda { |metrics| VmDiskSamplesHistory.disk_usage_rate_average_in_kilobytes_per_second(metrics[:disk]) },
|
48
|
+
:counter => {
|
49
|
+
:counter_key => "disk_usage_rate_average",
|
50
|
+
:instance => "",
|
51
|
+
:capture_interval => "20",
|
52
|
+
:precision => 2,
|
53
|
+
:rollup => "average",
|
54
|
+
:unit_key => "kilobytespersecond",
|
55
|
+
:capture_interval_name => "realtime"
|
56
|
+
}
|
57
|
+
},
|
58
|
+
|
59
|
+
"net_usage_rate_average" => {
|
60
|
+
:ovirt_key => :net_usage_rate_average,
|
61
|
+
:ovirt_method => lambda { |metrics| VmInterfaceSamplesHistory.net_usage_rate_average_in_kilobytes_per_second(metrics[:nic]) },
|
62
|
+
:counter => {
|
63
|
+
:counter_key => "net_usage_rate_average",
|
64
|
+
:instance => "",
|
65
|
+
:capture_interval => "20",
|
66
|
+
:precision => 2,
|
67
|
+
:rollup => "average",
|
68
|
+
:unit_key => "kilobytespersecond",
|
69
|
+
:capture_interval_name => "realtime"
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
HOST_COLUMN_DEFINITIONS = {
|
75
|
+
"cpu_usage_rate_average" => {
|
76
|
+
:ovirt_key => :cpu_usage_rate_average,
|
77
|
+
:ovirt_method => lambda { |metrics| metrics[:metric].cpu_usage_percent.to_f },
|
78
|
+
:counter => {
|
79
|
+
:counter_key => "cpu_usage_rate_average",
|
80
|
+
:instance => "",
|
81
|
+
:capture_interval => "20",
|
82
|
+
:precision => 1,
|
83
|
+
:rollup => "average",
|
84
|
+
:unit_key => "percent",
|
85
|
+
:capture_interval_name => "realtime"
|
86
|
+
}
|
87
|
+
},
|
88
|
+
|
89
|
+
"cpu_usagemhz_rate_average" => {
|
90
|
+
:ovirt_key => :cpu_usagemhz_rate_average,
|
91
|
+
:ovirt_method => lambda { |metrics| metrics[:metric].cpu_usagemhz_rate_average },
|
92
|
+
:counter => {
|
93
|
+
:counter_key => "cpu_usagemhz_rate_average",
|
94
|
+
:instance => "",
|
95
|
+
:capture_interval => "20",
|
96
|
+
:precision => 2,
|
97
|
+
:rollup => "average",
|
98
|
+
:unit_key => "megahertz",
|
99
|
+
:capture_interval_name => "realtime"
|
100
|
+
}
|
101
|
+
},
|
102
|
+
|
103
|
+
"mem_usage_absolute_average" => {
|
104
|
+
:ovirt_key => :mem_usage_absolute_average,
|
105
|
+
:ovirt_method => lambda { |metrics| metrics[:metric].memory_usage_percent.to_f },
|
106
|
+
:counter => {
|
107
|
+
:counter_key => "mem_usage_absolute_average",
|
108
|
+
:instance => "",
|
109
|
+
:capture_interval => "20",
|
110
|
+
:precision => 1,
|
111
|
+
:rollup => "average",
|
112
|
+
:unit_key => "percent",
|
113
|
+
:capture_interval_name => "realtime"
|
114
|
+
}
|
115
|
+
},
|
116
|
+
|
117
|
+
"net_usage_rate_average" => {
|
118
|
+
:ovirt_key => :net_usage_rate_average,
|
119
|
+
:ovirt_method => lambda { |metrics| HostInterfaceSamplesHistory.net_usage_rate_average_in_kilobytes_per_second(metrics[:nic]) },
|
120
|
+
:counter => {
|
121
|
+
:counter_key => "net_usage_rate_average",
|
122
|
+
:instance => "",
|
123
|
+
:capture_interval => "20",
|
124
|
+
:precision => 2,
|
125
|
+
:rollup => "average",
|
126
|
+
:unit_key => "kilobytespersecond",
|
127
|
+
:capture_interval_name => "realtime"
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
end
|