mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Move clone metric-gathering to 'get_clone_metrics' helper
This commit is contained in:
parent
1397ff93c1
commit
201897214b
1 changed files with 25 additions and 18 deletions
|
|
@ -26,6 +26,30 @@ module Vmpooler
|
||||||
capacity
|
capacity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_clone_metrics(date)
|
||||||
|
clone = {
|
||||||
|
duration: {
|
||||||
|
average: 0,
|
||||||
|
min: 0,
|
||||||
|
max: 0
|
||||||
|
},
|
||||||
|
count: {
|
||||||
|
total: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clone[:count][:total] = $redis.hlen('vmpooler__clone__' + date).to_i
|
||||||
|
|
||||||
|
if clone[:count][:total] > 0
|
||||||
|
clone_times = get_clone_times(date)
|
||||||
|
|
||||||
|
clone[:duration][:average] = (clone_times.reduce(:+).to_f / clone[:count][:total]).round(1)
|
||||||
|
clone[:duration][:min], clone[:duration][:max] = clone_times.minmax
|
||||||
|
end
|
||||||
|
|
||||||
|
clone
|
||||||
|
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
|
||||||
|
|
@ -81,21 +105,12 @@ module Vmpooler
|
||||||
status: {
|
status: {
|
||||||
ok: true,
|
ok: true,
|
||||||
message: 'Battle station fully armed and operational.'
|
message: 'Battle station fully armed and operational.'
|
||||||
},
|
|
||||||
clone: {
|
|
||||||
duration: {
|
|
||||||
average: 0,
|
|
||||||
min: 0,
|
|
||||||
max: 0
|
|
||||||
},
|
|
||||||
count: {
|
|
||||||
total: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result[:capacity] = get_capacity_metrics()
|
result[:capacity] = get_capacity_metrics()
|
||||||
result[:queue] = get_queue_metrics()
|
result[:queue] = get_queue_metrics()
|
||||||
|
result[:clone] = get_clone_metrics(Date.today.to_s)
|
||||||
|
|
||||||
# Check for empty pools
|
# Check for empty pools
|
||||||
$config[:pools].each do |pool|
|
$config[:pools].each do |pool|
|
||||||
|
|
@ -108,14 +123,6 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
result[:clone][:count][:total] = $redis.hlen('vmpooler__clone__' + Date.today.to_s).to_i
|
|
||||||
if result[:clone][:count][:total] > 0
|
|
||||||
clone_times = get_clone_times(Date.today)
|
|
||||||
|
|
||||||
result[:clone][:duration][:average] = (clone_times.reduce(:+).to_f / result[:clone][:count][:total]).round(1)
|
|
||||||
result[:clone][:duration][:min], result[:clone][:duration][:max] = clone_times.minmax
|
|
||||||
end
|
|
||||||
|
|
||||||
result[:status][:uptime] = (Time.now - $config[:uptime]).round(1) if $config[:uptime]
|
result[:status][:uptime] = (Time.now - $config[:uptime]).round(1) if $config[:uptime]
|
||||||
|
|
||||||
JSON.pretty_generate(Hash[result.sort_by { |k, _v| k }])
|
JSON.pretty_generate(Hash[result.sort_by { |k, _v| k }])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue