Pool stats should still work without graphite

This commit is contained in:
Scott Schneider 2013-12-12 11:22:52 -08:00
parent 7e3169bc70
commit b264104643

View file

@ -59,28 +59,35 @@ get '/dashboard/stats/vcloud/pool' do
end end
if ( params[:history] ) if ( params[:history] )
history ||= Hash.new if ( config[:config]['graphite'] )
history ||= Hash.new
buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.ready.*&from=-1hour&format=json' ).read buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.ready.*&from=-1hour&format=json' ).read
history = JSON.parse( buffer ) history = JSON.parse( buffer )
history.each do |pool| history.each do |pool|
if pool['target'] =~ /.*\.(.*)$/ if pool['target'] =~ /.*\.(.*)$/
pool['name'] = $1 pool['name'] = $1
pool['last'] = result[pool['name']]['size'] pool['last'] = result[pool['name']]['size']
result[pool['name']]['history'] ||= Array.new result[pool['name']]['history'] ||= Array.new
pool['datapoints'].each do |metric| pool['datapoints'].each do |metric|
8.times do |n| 8.times do |n|
if ( metric[0] ) if ( metric[0] )
pool['last'] = metric[0].to_i pool['last'] = metric[0].to_i
result[pool['name']]['history'].push( metric[0].to_i ) result[pool['name']]['history'].push( metric[0].to_i )
else else
result[pool['name']]['history'].push( pool['last'] ) result[pool['name']]['history'].push( pool['last'] )
end
end end
end end
end end
end end
else
config[:pools].each do |pool|
result[pool['name']] ||= Hash.new
result[pool['name']]['history'] = [ $redis.scard( 'vmware_host_pool__ready__' + pool['name'] ) ]
end
end end
end end