mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Record clone times in Redis, add a '/status' API endpoint
This commit is contained in:
parent
11016fecdc
commit
ecd17606f6
2 changed files with 43 additions and 0 deletions
|
|
@ -168,6 +168,47 @@ module Vmpooler
|
|||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get '/status/?' do
|
||||
content_type :json
|
||||
|
||||
result = {}
|
||||
clone_times = []
|
||||
|
||||
result['capacity_current'] = 0
|
||||
result['capacity_total'] = 0
|
||||
|
||||
result['status'] = 1
|
||||
|
||||
$config[:pools].each do |pool|
|
||||
pool['capacity_current'] = $redis.scard( 'vmpooler__ready__' + pool['name'] ).to_i
|
||||
|
||||
result['capacity_current'] += pool['capacity_current']
|
||||
result['capacity_total'] += pool['size'].to_i
|
||||
|
||||
if ( pool['capacity_current'] == 0 )
|
||||
result['empty'] ||= []
|
||||
result['empty'].push( pool['name'] )
|
||||
end
|
||||
|
||||
$redis.smembers( 'vmpooler__ready__'+pool['name'] ).each do |vm|
|
||||
clone_time = $redis.hget( 'vmpooler__vm__'+vm, 'clone_time' )
|
||||
clone_times.push( clone_time ) if clone_time.to_f > 0
|
||||
end
|
||||
end
|
||||
|
||||
if ( result['empty'] )
|
||||
result['status'] = 0
|
||||
end
|
||||
|
||||
if ( clone_times.any? )
|
||||
result['clone_average'] = clone_times.map( &:to_f ).reduce( :+ ) / clone_times.size
|
||||
end
|
||||
|
||||
result['capacity_perecent'] = ( result['capacity_current'].to_f / result['capacity_total'].to_f ) * 100.0
|
||||
|
||||
JSON.pretty_generate(Hash[result.sort_by{|k,v| k}])
|
||||
end
|
||||
|
||||
get '/vm/?' do
|
||||
content_type :json
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue