Module: RailsMonitor::Monitoring::ClassMethods
- Defined in:
- lib/rails_monitor.rb
Instance Method Summary collapse
- #boolean_status(name) ⇒ Object
- #numeric_status(name, default_warn_threshold = nil, default_error_threshold = nil) ⇒ Object
- #status_tab(anchor, statuses_to_show = []) ⇒ Object
Instance Method Details
#boolean_status(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_monitor.rb', line 34 def boolean_status(name) raise ArgumentError('No block given') unless block_given? define_method(name) do result = yield if result render_text_plain "OK: #{result}" else render_text_plain "ERROR: #{result}" end end end |
#numeric_status(name, default_warn_threshold = nil, default_error_threshold = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rails_monitor.rb', line 48 def numeric_status(name, default_warn_threshold = nil, default_error_threshold = nil) raise ArgumentError('No block given') unless block_given? define_method(name) do result = yield.to_i warn_threshold = default_warn_threshold || params[:warn_threshold] error_threshold = default_error_threshold || params[:error_threshold] if error_threshold && result >= error_threshold.to_i render_text_plain "ERROR: #{result}" elsif warn_threshold && result >= warn_threshold.to_i render_text_plain "WARN: #{result}" else render_text_plain "OK: #{result}" end end end |
#status_tab(anchor, statuses_to_show = []) ⇒ Object
30 31 32 |
# File 'lib/rails_monitor.rb', line 30 def status_tab(anchor, statuses_to_show = []) self.statuses[anchor] = statuses_to_show end |