1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Merge branch 'feature-696' of git.opennebula.org:one into feature-696

Conflicts:
	src/acct/watch_helper.rb
This commit is contained in:
Jaime Melis 2011-07-08 16:54:15 +02:00
commit b67d0aa774
5 changed files with 69 additions and 25 deletions

View File

@ -11,6 +11,8 @@ module OneWatch
sql.add_sample_from_resource(elem, timestamp)
}
end
sql_elem.flush
end
private
@ -25,8 +27,12 @@ module OneWatch
'VM'
end
def sql_elem(elem)
WatchHelper::Vm.info(elem)
def sql_elem(elem=nil)
if elem
WatchHelper::Vm.info(elem)
else
WatchHelper::Vm
end
end
end
@ -35,8 +41,12 @@ module OneWatch
'HOST'
end
def sql_elem(elem)
WatchHelper::Host.info(elem)
def sql_elem(elem=nil)
if elem
WatchHelper::Host.info(elem)
else
WatchHelper::Host
end
end
end
end
end

View File

@ -77,7 +77,9 @@ module OneWatchClient
"GROUP BY #{kind.downcase}_id, last_poll) " <<
"GROUP BY last_poll;"
) do |row|
a << [row[:last_poll], row["sum_#{mr}"]]
if row[:last_poll] && row[:last_poll] != 0
a << [row[:last_poll], row["sum_#{mr}"].to_i]
end
end
a
@ -109,13 +111,15 @@ module OneWatchClient
if allowed_sample.has_key?(mr.to_sym)
mon[mr] = Array.new
else
opts.remove(opt)
monitoring_resources.delete(mr)
end
}
rsql.samples_dataset.map { |sample|
monitoring_resources.each { |mr|
mon[mr] << [sample.last_poll, sample.send(mr.to_sym)]
if sample.last_poll && sample.last_poll != 0
mon[mr] << [sample.last_poll, sample.send(mr.to_sym)]
end
}
}

View File

@ -54,7 +54,7 @@ module WatchHelper
:type => Integer,
:path => 'MAX_MEM'
},
:mem_cpu => {
:max_cpu => {
:type => Integer,
:path => 'MAX_CPU'
},
@ -194,7 +194,7 @@ module WatchHelper
many_to_one :host
def self.active
self.filter(:state<3)
self.filter('state < 3')
end
def self.error
@ -237,10 +237,9 @@ module WatchHelper
one_to_many :deltas, :order=>:timestamp
# Monitoring
one_to_many :samples,
:before_add=>:control_regs,
:order=>:timestamp,
:class=>VmSample
one_to_many :samples, :order=>:timestamp, :class=>VmSample
@@samples_cache = []
@@vm_window_size = WatchHelper::get_config(
:VM_MONITORING,
@ -287,7 +286,7 @@ module WatchHelper
hash[key] = vm[value[:path]]
}
self.add_sample(hash)
@@samples_cache << hash
end
def add_delta_from_resource(vm, timestamp)
@ -296,6 +295,18 @@ module WatchHelper
self.add_sample(vs)
end
def self.flush
VmSample.multi_insert(@@samples_cache)
Vm.each { |vm|
if vm.samples.count > @@vm_window_size -1
vm.samples.last.delete
end
}
@@samples_cache = []
end
private
def control_regs(sample)
@ -309,16 +320,16 @@ module WatchHelper
unrestrict_primary_key
# Monitoring
one_to_many :samples,
:before_add=>:control_regs,
:order=>:timestamp,
:class=>HostSample
one_to_many :samples, :order=>:timestamp, :class=>HostSample
@@samples_cache = []
@@host_window_size = WatchHelper::get_config(
:HOST_MONITORING,
:WINDOW_SIZE
)
def self.info(host)
Host.find_or_create(:id=>host['ID']) { |h|
h.name = host['NAME']
@ -328,8 +339,21 @@ module WatchHelper
}
end
def self.flush
HostSample.multi_insert(@@samples_cache)
Host.each { |host|
if host.samples.count > @@host_window_size -1
host.samples.last.delete
end
}
@@samples_cache = []
end
def add_sample_from_resource(host, timestamp)
hash = {
:host_id => host['ID'],
:timestamp => timestamp,
:last_poll => host['LAST_MON_TIME'],
:state => host['STATE'],
@ -340,7 +364,7 @@ module WatchHelper
hash[key] = host_share[value[:path]]
}
self.add_sample(hash)
@@samples_cache << hash
end
private

View File

@ -280,9 +280,9 @@ class SunstoneServer
#
############################################################################
def get_monitoring(id, resource, monitoring_resources)
def get_monitoring(id, resource, monitor_resources)
watch_client = OneWatchClient::WatchClient.new
columns = params['monitor_resources'].split(',')
columns = monitor_resources.split(',')
rc = case resource
when "vm","VM"
@ -301,6 +301,11 @@ class SunstoneServer
return [200, nil]
end
if rc.nil?
error = Error.new("There is no monitoring information for #{resource} #{id}")
return [500, error.to_json]
end
return [200, rc.to_json]
end

View File

@ -168,16 +168,17 @@ end
get '/:resource/monitor' do
@SunstoneServer.get_monitoring(
params[:id],
nil,
params[:resource],
params[:monitoring_resources]
params[:monitor_resources]
)
end
get '/:resource/:id/monitor' do
@SunstoneServer.get_monitoring(
params[:id],
params[:resource],
params[:monitoring_resources]
params[:monitor_resources]
)
end