mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Store and retrieve daily clone statistics from Redis db
This commit is contained in:
parent
3758e5e3f3
commit
d6ade5ebef
3 changed files with 5 additions and 10 deletions
|
|
@ -172,7 +172,6 @@ module Vmpooler
|
|||
content_type :json
|
||||
|
||||
result = {}
|
||||
clone_times = []
|
||||
|
||||
result['capacity_current'] = 0
|
||||
result['capacity_total'] = 0
|
||||
|
|
@ -189,23 +188,17 @@ module Vmpooler
|
|||
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
|
||||
|
||||
result['clone_total'] = $redis.hlen('vmpooler__clone__'+Date.today.to_s)
|
||||
result['clone_average'] = $redis.hvals('vmpooler__clone__'+Date.today.to_s).map( &:to_f ).reduce( :+ ) / result['clone_total']
|
||||
|
||||
JSON.pretty_generate(Hash[result.sort_by{|k,v| k}])
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue