mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Move capacity metric-gathering to 'get_capacity_metrics' helper
This commit is contained in:
parent
fd0e5cb438
commit
1397ff93c1
1 changed files with 27 additions and 18 deletions
|
|
@ -5,6 +5,27 @@ module Vmpooler
|
||||||
api_prefix = "/api/v#{api_version}"
|
api_prefix = "/api/v#{api_version}"
|
||||||
|
|
||||||
helpers do
|
helpers do
|
||||||
|
def get_capacity_metrics()
|
||||||
|
capacity = {
|
||||||
|
current: 0,
|
||||||
|
total: 0,
|
||||||
|
percent: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
$config[:pools].each do |pool|
|
||||||
|
pool['capacity'] = $redis.scard('vmpooler__ready__' + pool['name']).to_i
|
||||||
|
|
||||||
|
capacity[:current] += pool['capacity']
|
||||||
|
capacity[:total] += pool['size'].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
if capacity[:total] > 0
|
||||||
|
capacity[:percent] = ((capacity[:current].to_f / capacity[:total].to_f) * 100.0).round(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
capacity
|
||||||
|
end
|
||||||
|
|
||||||
def get_clone_times(date)
|
def get_clone_times(date)
|
||||||
$redis.hvals('vmpooler__clone__' + date.to_s).map(&:to_f)
|
$redis.hvals('vmpooler__clone__' + date.to_s).map(&:to_f)
|
||||||
end
|
end
|
||||||
|
|
@ -61,11 +82,6 @@ module Vmpooler
|
||||||
ok: true,
|
ok: true,
|
||||||
message: 'Battle station fully armed and operational.'
|
message: 'Battle station fully armed and operational.'
|
||||||
},
|
},
|
||||||
capacity: {
|
|
||||||
current: 0,
|
|
||||||
total: 0,
|
|
||||||
percent: 0
|
|
||||||
},
|
|
||||||
clone: {
|
clone: {
|
||||||
duration: {
|
duration: {
|
||||||
average: 0,
|
average: 0,
|
||||||
|
|
@ -78,26 +94,19 @@ module Vmpooler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result[:capacity] = get_capacity_metrics()
|
||||||
result[:queue] = get_queue_metrics()
|
result[:queue] = get_queue_metrics()
|
||||||
|
|
||||||
|
# Check for empty pools
|
||||||
$config[:pools].each do |pool|
|
$config[:pools].each do |pool|
|
||||||
pool['capacity'] = $redis.scard('vmpooler__ready__' + pool['name']).to_i
|
if $redis.scard('vmpooler__ready__' + pool['name']).to_i == 0
|
||||||
|
|
||||||
result[:capacity][:current] += pool['capacity']
|
|
||||||
result[:capacity][:total] += pool['size'].to_i
|
|
||||||
|
|
||||||
if (pool['capacity'] == 0)
|
|
||||||
result[:status][:empty] ||= []
|
result[:status][:empty] ||= []
|
||||||
result[:status][:empty].push(pool['name'])
|
result[:status][:empty].push(pool['name'])
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if result[:status][:empty]
|
|
||||||
result[:status][:ok] = false
|
result[:status][:ok] = false
|
||||||
result[:status][:message] = "Found #{result[:status][:empty].length} empty pools."
|
result[:status][:message] = "Found #{result[:status][:empty].length} empty pools."
|
||||||
end
|
end
|
||||||
|
end
|
||||||
result[:capacity][:percent] = ((result[:capacity][:current].to_f / result[:capacity][:total].to_f) * 100.0).round(1) if result[:capacity][:total] > 0
|
|
||||||
|
|
||||||
result[:clone][:count][:total] = $redis.hlen('vmpooler__clone__' + Date.today.to_s).to_i
|
result[:clone][:count][:total] = $redis.hlen('vmpooler__clone__' + Date.today.to_s).to_i
|
||||||
if result[:clone][:count][:total] > 0
|
if result[:clone][:count][:total] > 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue