Skip to content

Commit

Permalink
NOR covers 30 days
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswnl committed May 2, 2018
1 parent 388f266 commit 448155f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/models/metric/long_term_averages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def self.get_averages_over_time_period(obj, options = {})
avg_cols = options[:avg_cols] || AVG_COLS

ext_options = ext_options.merge(:only_cols => avg_cols)
perfs = VimPerformanceAnalysis.find_perf_for_time_period(obj, "daily", :end_date => Time.now.utc, :days => avg_days, :ext_options => ext_options)
end_date = Time.now.utc.beginning_of_day - 1
perfs = VimPerformanceAnalysis.find_perf_for_time_period(obj, "daily", :end_date => end_date, :days => avg_days, :ext_options => ext_options)
perfs.each do |p|
if ext_options[:time_profile] && !ext_options[:time_profile].ts_day_in_profile?(p.timestamp.in_time_zone(tz))
next
Expand Down
7 changes: 7 additions & 0 deletions app/models/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class Vm < VmOrTemplate

include_concern 'Operations'

def mystats
byebug
max_mem_usage_absolute_average_high_over_time_period
max_mem_usage_absolute_average_avg_over_time_period
max_mem_usage_absolute_average_low_over_time_period
max_mem_usage_absolute_average_max_over_time_period
end
def self.base_model
Vm
end
Expand Down
12 changes: 8 additions & 4 deletions app/models/vm_or_template/right_sizing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def mem_recommendation_minimum
alias_method :overallocated_mem_pct, :aggressive_mem_recommended_change_pct

def max_cpu_usage_rate_average_max_over_time_period
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS)
end_date = Time.now.utc.beginning_of_day - 1
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS)
perfs.collect do |p|
# Ignore any CPU bursts to 100% 15 minutes after VM booted
next if (p.abs_max_cpu_usage_rate_average_value == 100.0) && boot_time && (p.abs_max_cpu_usage_rate_average_timestamp <= (boot_time + 15.minutes))
Expand All @@ -158,17 +159,20 @@ def max_cpu_usage_rate_average_max_over_time_period
end

def max_mem_usage_absolute_average_max_over_time_period
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS)
end_date = Time.now.utc.beginning_of_day - 1
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS)
perfs.collect(&:abs_max_mem_usage_absolute_average_value).compact.max
end

def cpu_usagemhz_rate_average_max_over_time_period
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS)
end_date = Time.now.utc.beginning_of_day - 1
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS)
perfs.collect(&:abs_max_cpu_usagemhz_rate_average_value).compact.max
end

def derived_memory_used_max_over_time_period
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => Time.now.utc, :days => Metric::LongTermAverages::AVG_DAYS)
end_date = Time.now.utc.beginning_of_day - 1
perfs = VimPerformanceAnalysis.find_perf_for_time_period(self, "daily", :end_date => end_date, :days => Metric::LongTermAverages::AVG_DAYS)
perfs.collect(&:abs_max_derived_memory_used_value).compact.max
end

Expand Down
5 changes: 3 additions & 2 deletions spec/models/metric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@
before do
Timecop.travel(Time.parse("2010-05-01T00:00:00Z"))
cases = [
"2010-04-01T00:00:00Z", 9.14, 32.85,
"2010-04-13T21:00:00Z", 9.14, 32.85,
"2010-04-14T18:00:00Z", 10.23, 28.76,
"2010-04-14T19:00:00Z", 18.92, 39.11,
Expand Down Expand Up @@ -669,8 +670,8 @@
it "should calculate the correct normal operating range values" do
@vm1.generate_vim_performance_operating_range(@time_profile)

expect(@vm1.max_cpu_usage_rate_average_avg_over_time_period).to be_within(0.001).of(13.692)
expect(@vm1.max_mem_usage_absolute_average_avg_over_time_period).to be_within(0.001).of(33.085)
expect(@vm1.max_cpu_usage_rate_average_avg_over_time_period).to be_within(0.001).of(13.124)
expect(@vm1.max_mem_usage_absolute_average_avg_over_time_period).to be_within(0.001).of(33.056)
end

it "should calculate the correct right-size values" do
Expand Down

0 comments on commit 448155f

Please sign in to comment.