mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(QENG-1873) Match status endpoint
These changes are to match the status endpoints JSON payload. This also introduces both clone timings and information on total clones. The field "day" is renamed to "date" to accomodate when from/to will include times.
This commit is contained in:
parent
34a6355940
commit
ef333ca65f
1 changed files with 51 additions and 19 deletions
|
|
@ -35,6 +35,11 @@ module Vmpooler
|
||||||
def validate_date_str(date_str)
|
def validate_date_str(date_str)
|
||||||
/^\d{4}-\d{2}-\d{2}$/ === date_str
|
/^\d{4}-\d{2}-\d{2}$/ === date_str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mean(list)
|
||||||
|
s = list.map(&:to_f).reduce(:+).to_f
|
||||||
|
(s > 0 && list.length > 0) ? s / list.length.to_f : 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
|
|
@ -205,8 +210,17 @@ module Vmpooler
|
||||||
|
|
||||||
get '/summary/?' do
|
get '/summary/?' do
|
||||||
result = {
|
result = {
|
||||||
clone_total: 0,
|
clone: {
|
||||||
clone_average: 0,
|
duration: {
|
||||||
|
average: 0,
|
||||||
|
min: 0,
|
||||||
|
max: 0
|
||||||
|
},
|
||||||
|
average: 0,
|
||||||
|
min: 0,
|
||||||
|
max: 0,
|
||||||
|
total: 0
|
||||||
|
},
|
||||||
daily: [] # used for daily info
|
daily: [] # used for daily info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -235,36 +249,54 @@ module Vmpooler
|
||||||
|
|
||||||
# total clone time for entire duration requested.
|
# total clone time for entire duration requested.
|
||||||
total_clone_time = 0
|
total_clone_time = 0
|
||||||
|
min_max_clone_times = [] # min/max clone times from each day.
|
||||||
|
total_clones_per_day = [] # total clones from each day
|
||||||
|
|
||||||
# generate sequence/range for from_date to to_date (inclusive).
|
# generate sequence/range for from_date to to_date (inclusive).
|
||||||
# for each date, calculate the day's clone total & average, as well
|
# for each date, calculate the day's clone total & average, as well
|
||||||
# as add to total/overall values.
|
# as add to total/overall values.
|
||||||
(from_date..to_date).each do |date|
|
(from_date..to_date).each do |date|
|
||||||
me = {
|
me = {
|
||||||
day: date.to_s,
|
date: date.to_s,
|
||||||
clone_total: $redis.hlen('vmpooler__clone__' + date.to_s),
|
clone: {
|
||||||
clone_average: 0
|
average: 0,
|
||||||
|
min: 0,
|
||||||
|
max: 0,
|
||||||
|
total: $redis.hlen('vmpooler__clone__' + date.to_s).to_i,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result[:clone_total] += me[:clone_total]
|
result[:clone][:total] += me[:clone][:total]
|
||||||
|
total_clones_per_day.push(me[:clone][:total])
|
||||||
|
|
||||||
clone_time = $redis.hvals('vmpooler__clone__' + date.to_s).map(&:to_f).reduce(:+)
|
clone_times = $redis.hvals('vmpooler__clone__' + date.to_s)
|
||||||
total_clone_time += clone_time.to_f
|
|
||||||
|
|
||||||
# if clone_total > 0, calculate clone_average.
|
unless clone_times.nil? or clone_times.empty?
|
||||||
# this prevents divide by 0 problems.
|
clone_time = clone_times.map(&:to_f).reduce(:+).to_f
|
||||||
if me[:clone_total] > 0
|
total_clone_time += clone_time
|
||||||
me[:clone_average] = clone_time / me[:clone_total]
|
|
||||||
else
|
me[:clone][:min], me[:clone][:max] = clone_times.minmax
|
||||||
me[:clone_average] = 0
|
min_max_clone_times.push(me[:clone][:min])
|
||||||
|
min_max_clone_times.push(me[:clone][:max])
|
||||||
|
|
||||||
|
# if clone_total > 0, calculate clone_average.
|
||||||
|
# this prevents divide by 0 problems.
|
||||||
|
if me[:clone][:total] > 0
|
||||||
|
me[:clone][:average] = clone_time / me[:clone][:total]
|
||||||
|
else
|
||||||
|
me[:clone][:average] = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# add to daily array
|
||||||
|
result[:daily].push(me)
|
||||||
end
|
end
|
||||||
|
|
||||||
# add to daily array
|
|
||||||
result[:daily].push(me)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# again, calc clone_average if we had clones.
|
# again, calc clone_average if we had clones.
|
||||||
if result[:clone_total] > 0
|
if result[:clone][:total] > 0
|
||||||
result[:clone_average] = total_clone_time / result[:clone_total]
|
result[:clone][:timings][:average] = total_clone_time / result[:clone][:total]
|
||||||
|
result[:clone][:timings][:min], result[:clone][:timings][:max] = min_max_clone_times.minmax
|
||||||
|
result[:clone][:min], result[:clone][:max] = total_clones_per_day.minmax
|
||||||
|
result[:clone][:average] = mean(total_clones_per_day)
|
||||||
end
|
end
|
||||||
|
|
||||||
content_type :json
|
content_type :json
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue