Module: Anomonitor::ApplicationHelper
- Includes:
- ActionView::Helpers::DateHelper, ActionView::Helpers::NumberHelper
- Defined in:
- app/helpers/anomonitor/application_helper.rb
Instance Method Summary collapse
- #anomaly_status_badge_class(anomaly) ⇒ Object
- #format_metric(value) ⇒ Object
- #job_status_badge_class(status) ⇒ Object
- #poller_cron?(status = nil) ⇒ Boolean
- #poller_last_run_label(status) ⇒ Object
- #poller_mode(status = nil) ⇒ Object
- #poller_mode_label(status = nil) ⇒ Object
- #poller_schedule_label(status) ⇒ Object
- #poller_state_badge_class(status) ⇒ Object
- #poller_state_label(status) ⇒ Object
Instance Method Details
#anomaly_status_badge_class(anomaly) ⇒ Object
67 68 69 |
# File 'app/helpers/anomonitor/application_helper.rb', line 67 def anomaly_status_badge_class(anomaly) anomaly.open? ? "warn" : "ok" end |
#format_metric(value) ⇒ Object
52 53 54 55 56 |
# File 'app/helpers/anomonitor/application_helper.rb', line 52 def format_metric(value) return "—" if value.nil? number_with_precision(value, precision: 0, delimiter: ",") end |
#job_status_badge_class(status) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'app/helpers/anomonitor/application_helper.rb', line 58 def job_status_badge_class(status) case status.to_s when "failed" then "danger" when "locked" then "warn" when "pending" then "ok" else "" end end |
#poller_cron?(status = nil) ⇒ Boolean
17 18 19 |
# File 'app/helpers/anomonitor/application_helper.rb', line 17 def poller_cron?(status = nil) poller_mode(status).to_s == "cron" end |
#poller_last_run_label(status) ⇒ Object
45 46 47 48 49 50 |
# File 'app/helpers/anomonitor/application_helper.rb', line 45 def poller_last_run_label(status) last = status[:last_run_at] || status["last_run_at"] return "never" unless last "#{time_ago_in_words(last)} ago" end |
#poller_mode(status = nil) ⇒ Object
8 9 10 11 |
# File 'app/helpers/anomonitor/application_helper.rb', line 8 def poller_mode(status = nil) mode = status && (status[:poll_mode] || status["poll_mode"]) mode || Anomonitor.config.poll_mode end |
#poller_mode_label(status = nil) ⇒ Object
13 14 15 |
# File 'app/helpers/anomonitor/application_helper.rb', line 13 def poller_mode_label(status = nil) poller_mode(status).to_s == "cron" ? "cron" : "thread" end |
#poller_schedule_label(status) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/helpers/anomonitor/application_helper.rb', line 37 def poller_schedule_label(status) if poller_cron?(status) "rails anomonitor:poll" else "#{status[:poll_interval] || status["poll_interval"] || Anomonitor.config.poll_interval}s" end end |
#poller_state_badge_class(status) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/helpers/anomonitor/application_helper.rb', line 29 def poller_state_badge_class(status) if poller_cron?(status) (status[:last_run_at] || status["last_run_at"]) ? "ok" : "warn" else (status[:running] || status["running"]) ? "ok" : "warn" end end |
#poller_state_label(status) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/helpers/anomonitor/application_helper.rb', line 21 def poller_state_label(status) if poller_cron?(status) status[:last_run_at] || status["last_run_at"] ? "scheduled" : "waiting for first poll" else (status[:running] || status["running"]) ? "running" : "stopped" end end |