mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Merge branch 'master' into external_redis
This commit is contained in:
commit
b9c7ef265b
9 changed files with 282 additions and 11 deletions
|
|
@ -114,6 +114,55 @@ get '/dashboard/stats/vcloud/pool' do
|
|||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get '/dashboard/stats/vcloud/running' do
|
||||
result = Hash.new
|
||||
|
||||
config[:pools].each do |pool|
|
||||
running = $redis.scard( 'vmware_host_pool__running__' + pool['name'] )
|
||||
pool['major'] = $1 if pool['name'] =~ /^(\w+)\-/
|
||||
|
||||
result[pool['major']] ||= Hash.new
|
||||
|
||||
result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
|
||||
end
|
||||
|
||||
if ( params[:history] )
|
||||
if ( config[:config]['graphite'] )
|
||||
begin
|
||||
buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.running.*&from=-1hour&format=json' ).read
|
||||
JSON.parse( buffer ).each do |pool|
|
||||
if pool['target'] =~ /.*\.(.*)$/
|
||||
pool['name'] = $1
|
||||
|
||||
pool['major'] = $1 if pool['name'] =~ /^(\w+)\-/
|
||||
|
||||
result[pool['major']]['history'] ||= Array.new
|
||||
|
||||
for i in 0..pool['datapoints'].length
|
||||
if (
|
||||
pool['datapoints'][i] and
|
||||
pool['datapoints'][i][0]
|
||||
)
|
||||
pool['last'] = pool['datapoints'][i][0]
|
||||
|
||||
result[pool['major']]['history'][i] ||= 0
|
||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['datapoints'][i][0].to_i
|
||||
else
|
||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
content_type :json
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get '/status' do
|
||||
content_type :json
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue