Class: Checkups::Performance

Inherits:
Checkup
  • Object
show all
Defined in:
lib/checkups/performance.rb

Instance Attribute Summary collapse

Attributes inherited from Checkup

#name, #status, #status_message, #url, #verbose

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Checkup

#check_and_notify!, checkups_by_frequency, daily, hourly, #notify_message, #passed?

Constructor Details

#initialize(verbose: false, name: nil, warning_limit: 1800, error_limit: 3600) ⇒ Performance



11
12
13
14
15
16
17
# File 'lib/checkups/performance.rb', line 11

def initialize(verbose: false, name: nil, warning_limit: 1800, error_limit: 3600)
  super(verbose: verbose)
  @name = name
  @warning_limit = warning_limit
  @error_limit = error_limit
  ok
end

Instance Attribute Details

#error_limitObject (readonly)

Returns the value of attribute error_limit.



9
10
11
# File 'lib/checkups/performance.rb', line 9

def error_limit
  @error_limit
end

#warning_limitObject (readonly)

Returns the value of attribute warning_limit.



9
10
11
# File 'lib/checkups/performance.rb', line 9

def warning_limit
  @warning_limit
end

Class Method Details

.frequencyObject



5
6
7
# File 'lib/checkups/performance.rb', line 5

def self.frequency
  :never
end

Instance Method Details

#checkObject



19
20
21
22
23
# File 'lib/checkups/performance.rb', line 19

def check
  start_time = Time.now.to_i
  yield
  check_elapsed(Time.now.to_i - start_time)
end

#check_elapsed(elapsed) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/checkups/performance.rb', line 25

def check_elapsed(elapsed)
  if warning_limit <= elapsed && elapsed < error_limit
    warning "#{name} took longer than #{warning_limit}s: #{elapsed}s"
  elsif error_limit <= elapsed
    error "#{name} took longer than #{error_limit}s: #{elapsed}s"
  else
    ok
  end
end