mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-01 06:50:25 +03:00
M #-: Remove unneeded vCenter VMM poll
This commit is contained in:
parent
3cd0949dba
commit
c3d0e70f34
@ -1178,7 +1178,6 @@ VMM_EXEC_VCENTER_SCRIPTS="src/vmm_mad/remotes/vcenter/cancel \
|
||||
src/vmm_mad/remotes/vcenter/save \
|
||||
src/vmm_mad/remotes/vcenter/resize_disk \
|
||||
src/vmm_mad/remotes/vcenter/resize \
|
||||
src/vmm_mad/remotes/vcenter/poll \
|
||||
src/vmm_mad/remotes/vcenter/shutdown \
|
||||
src/vmm_mad/remotes/vcenter/reconfigure \
|
||||
src/vmm_mad/remotes/vcenter/preconfigure \
|
||||
|
@ -36,194 +36,6 @@ module VirtualMachineMonitor
|
||||
end
|
||||
end
|
||||
|
||||
# monitor function used when VMM poll action is called
|
||||
# rubocop:disable Naming/VariableName
|
||||
# rubocop:disable Style/FormatStringToken
|
||||
def monitor_poll_vm
|
||||
reset_monitor
|
||||
|
||||
return unless get_vm_id
|
||||
|
||||
@state = state_to_c(self['summary.runtime.powerState'])
|
||||
|
||||
if @state != OpenNebula::VirtualMachine::Driver::VM_STATE[:active]
|
||||
reset_monitor
|
||||
return
|
||||
end
|
||||
|
||||
cpuMhz = self['runtime.host.summary.hardware.cpuMhz'].to_f
|
||||
|
||||
@monitor[:used_memory] = self['summary.quickStats.hostMemoryUsage'] *
|
||||
1024
|
||||
|
||||
used_cpu = self['summary.quickStats.overallCpuUsage'].to_f / cpuMhz
|
||||
used_cpu = (used_cpu * 100).to_s
|
||||
@monitor[:used_cpu] = format('%.2f', used_cpu).to_s
|
||||
|
||||
# Check for negative values
|
||||
@monitor[:used_memory] = 0 if @monitor[:used_memory].to_i < 0
|
||||
@monitor[:used_cpu] = 0 if @monitor[:used_cpu].to_i < 0
|
||||
|
||||
guest_ip_addresses = []
|
||||
unless self['guest.net'].empty?
|
||||
self['guest.net'].each do |net|
|
||||
next unless net.ipConfig
|
||||
next if net.ipConfig.ipAddress.empty?
|
||||
|
||||
net.ipConfig.ipAddress.each do |ip|
|
||||
guest_ip_addresses << ip.ipAddress
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@guest_ip_addresses = guest_ip_addresses.join(',')
|
||||
|
||||
pm = self['_connection'].serviceInstance.content.perfManager
|
||||
|
||||
provider = pm.provider_summary(@item)
|
||||
|
||||
refresh_rate = provider.refreshRate
|
||||
|
||||
stats = {}
|
||||
|
||||
if one_item['MONITORING/LAST_MON'] &&
|
||||
one_item['MONITORING/LAST_MON'].to_i != 0
|
||||
# Real time data stores max 1 hour. 1 minute has 3 samples
|
||||
interval = (Time.now.to_i -
|
||||
one_item['MONITORING/LAST_MON'].to_i)
|
||||
|
||||
# If last poll was more than hour ago get 3 minutes,
|
||||
# else calculate how many samples since last poll
|
||||
if interval > 3600
|
||||
samples = 9
|
||||
else
|
||||
samples = (interval / refresh_rate) + 1
|
||||
end
|
||||
samples > 0 ? max_samples = samples : max_samples = 1
|
||||
|
||||
stats = pm.retrieve_stats(
|
||||
[@item],
|
||||
['net.transmitted', 'net.bytesRx', 'net.bytesTx',
|
||||
'net.received', 'virtualDisk.numberReadAveraged',
|
||||
'virtualDisk.numberWriteAveraged', 'virtualDisk.read',
|
||||
'virtualDisk.write'],
|
||||
interval => refresh_rate, max_samples => max_samples
|
||||
) rescue {}
|
||||
else
|
||||
# First poll, get at least latest 3 minutes = 9 samples
|
||||
stats = pm.retrieve_stats(
|
||||
[@item],
|
||||
['net.transmitted', 'net.bytesRx', 'net.bytesTx',
|
||||
'net.received', 'virtualDisk.numberReadAveraged',
|
||||
'virtualDisk.numberWriteAveraged', 'virtualDisk.read',
|
||||
'virtualDisk.write'],
|
||||
interval => refresh_rate, max_samples => 9
|
||||
) rescue {}
|
||||
end
|
||||
|
||||
if !stats.empty? && !stats.first[1][:metrics].empty?
|
||||
metrics = stats.first[1][:metrics]
|
||||
|
||||
nettx_kbpersec = 0
|
||||
if metrics['net.transmitted']
|
||||
metrics['net.transmitted'].each do |sample|
|
||||
nettx_kbpersec += sample if sample > 0
|
||||
end
|
||||
end
|
||||
|
||||
netrx_kbpersec = 0
|
||||
if metrics['net.bytesRx']
|
||||
metrics['net.bytesRx'].each do |sample|
|
||||
netrx_kbpersec += sample if sample > 0
|
||||
end
|
||||
end
|
||||
|
||||
read_kbpersec = 0
|
||||
if metrics['virtualDisk.read']
|
||||
metrics['virtualDisk.read'].each do |sample|
|
||||
read_kbpersec += sample if sample > 0
|
||||
end
|
||||
end
|
||||
|
||||
read_iops = 0
|
||||
if metrics['virtualDisk.numberReadAveraged']
|
||||
metrics['virtualDisk.numberReadAveraged'].each do |sample|
|
||||
read_iops += sample if sample > 0
|
||||
end
|
||||
end
|
||||
|
||||
write_kbpersec = 0
|
||||
if metrics['virtualDisk.write']
|
||||
metrics['virtualDisk.write'].each do |sample|
|
||||
write_kbpersec += sample if sample > 0
|
||||
end
|
||||
end
|
||||
|
||||
write_iops = 0
|
||||
if metrics['virtualDisk.numberWriteAveraged']
|
||||
metrics['virtualDisk.numberWriteAveraged'].each do |sample|
|
||||
write_iops += sample if sample > 0
|
||||
end
|
||||
end
|
||||
else
|
||||
nettx_kbpersec = 0
|
||||
netrx_kbpersec = 0
|
||||
read_kbpersec = 0
|
||||
read_iops = 0
|
||||
write_kbpersec = 0
|
||||
write_iops = 0
|
||||
end
|
||||
|
||||
# Accumulate values if present
|
||||
if @one_item && @one_item['MONITORING/NETTX']
|
||||
previous_nettx = @one_item['MONITORING/NETTX'].to_i
|
||||
else
|
||||
previous_nettx = 0
|
||||
end
|
||||
|
||||
if @one_item && @one_item['MONITORING/NETRX']
|
||||
previous_netrx = @one_item['MONITORING/NETRX'].to_i
|
||||
else
|
||||
previous_netrx = 0
|
||||
end
|
||||
|
||||
if @one_item && @one_item['MONITORING/DISKRDIOPS']
|
||||
previous_diskrdiops = @one_item['MONITORING/DISKRDIOPS'].to_i
|
||||
else
|
||||
previous_diskrdiops = 0
|
||||
end
|
||||
|
||||
if @one_item && @one_item['MONITORING/DISKWRIOPS']
|
||||
previous_diskwriops = @one_item['MONITORING/DISKWRIOPS'].to_i
|
||||
else
|
||||
previous_diskwriops = 0
|
||||
end
|
||||
|
||||
if @one_item && @one_item['MONITORING/DISKRDBYTES']
|
||||
previous_diskrdbytes = @one_item['MONITORING/DISKRDBYTES'].to_i
|
||||
else
|
||||
previous_diskrdbytes = 0
|
||||
end
|
||||
|
||||
if @one_item && @one_item['MONITORING/DISKWRBYTES']
|
||||
previous_diskwrbytes = @one_item['MONITORING/DISKWRBYTES'].to_i
|
||||
else
|
||||
previous_diskwrbytes = 0
|
||||
end
|
||||
|
||||
@monitor[:nettx] = previous_nettx +
|
||||
(nettx_kbpersec * 1024 * refresh_rate).to_i
|
||||
@monitor[:netrx] = previous_netrx +
|
||||
(netrx_kbpersec * 1024 * refresh_rate).to_i
|
||||
|
||||
@monitor[:diskrdiops] = previous_diskrdiops + read_iops
|
||||
@monitor[:diskwriops] = previous_diskwriops + write_iops
|
||||
@monitor[:diskrdbytes] = previous_diskrdbytes +
|
||||
(read_kbpersec * 1024 * refresh_rate).to_i
|
||||
@monitor[:diskwrbytes] = previous_diskwrbytes +
|
||||
(write_kbpersec * 1024 * refresh_rate).to_i
|
||||
end
|
||||
|
||||
# monitor function used when poll action is called for all vms
|
||||
def monitor(stats)
|
||||
reset_monitor
|
||||
|
@ -1,70 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION ||= ENV['ONE_LOCATION']
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION ||= '/usr/lib/one/ruby'
|
||||
GEMS_LOCATION ||= '/usr/share/one/gems'
|
||||
else
|
||||
RUBY_LIB_LOCATION ||= ONE_LOCATION + '/lib/ruby'
|
||||
GEMS_LOCATION ||= ONE_LOCATION + '/share/gems'
|
||||
end
|
||||
|
||||
if File.directory?(GEMS_LOCATION)
|
||||
real_gems_path = File.realpath(GEMS_LOCATION)
|
||||
if !defined?(Gem) || Gem.path != [real_gems_path]
|
||||
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
||||
require 'rubygems'
|
||||
Gem.use_paths(real_gems_path)
|
||||
end
|
||||
end
|
||||
|
||||
$LOAD_PATH << RUBY_LIB_LOCATION
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
|
||||
require 'vcenter_driver'
|
||||
|
||||
vm_ref = ARGV[0]
|
||||
vc_cluster_name = ARGV[1]
|
||||
vm_id = ARGV[2]
|
||||
|
||||
drv_action = OpenNebula::XMLElement.new
|
||||
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
|
||||
|
||||
host_id = drv_action['VM/HISTORY_RECORDS/HISTORY/HID']
|
||||
|
||||
begin
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)
|
||||
|
||||
vm.monitor_poll_vm
|
||||
|
||||
puts vm.info
|
||||
rescue StandardError => e
|
||||
message = "Cannot poll info for VM #{vm_ref} with OpenNebula id #{vm_id}" \
|
||||
" on vCenter cluster #{vc_cluster_name} failed due to " \
|
||||
"\"#{e.message}\"."
|
||||
OpenNebula.log_error(message)
|
||||
if VCenterDriver::CONFIG[:debug_information]
|
||||
STDERR.puts "#{message} #{e.backtrace}"
|
||||
end
|
||||
exit(-1)
|
||||
ensure
|
||||
vi_client.close_connection if vi_client
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user