From 45ab2455cf71fbdf3fbf2863e2d77b90d843390a Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Thu, 12 Dec 2013 11:22:52 -0800 Subject: [PATCH] Pool stats should still work without graphite --- vmware-host-pooler-api | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/vmware-host-pooler-api b/vmware-host-pooler-api index de9cda2..200f84b 100755 --- a/vmware-host-pooler-api +++ b/vmware-host-pooler-api @@ -59,28 +59,35 @@ get '/dashboard/stats/vcloud/pool' do end 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 - history = JSON.parse( buffer ) + buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.ready.*&from=-1hour&format=json' ).read + history = JSON.parse( buffer ) - history.each do |pool| - if pool['target'] =~ /.*\.(.*)$/ - pool['name'] = $1 - pool['last'] = result[pool['name']]['size'] - result[pool['name']]['history'] ||= Array.new + history.each do |pool| + if pool['target'] =~ /.*\.(.*)$/ + pool['name'] = $1 + pool['last'] = result[pool['name']]['size'] + result[pool['name']]['history'] ||= Array.new - pool['datapoints'].each do |metric| - 8.times do |n| - if ( metric[0] ) - pool['last'] = metric[0].to_i - result[pool['name']]['history'].push( metric[0].to_i ) - else - result[pool['name']]['history'].push( pool['last'] ) + pool['datapoints'].each do |metric| + 8.times do |n| + if ( metric[0] ) + pool['last'] = metric[0].to_i + result[pool['name']]['history'].push( metric[0].to_i ) + else + result[pool['name']]['history'].push( pool['last'] ) + 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