Class: SidekiqQueueStatus::FailureRate
- Inherits:
-
Metric
- Object
- Metric
- SidekiqQueueStatus::FailureRate
show all
- Defined in:
- lib/sidekiq_queue_status/failure_rate.rb
Constant Summary
collapse
- DEFAULT_FAILURE_RATE_PERC =
10
Instance Attribute Summary
Attributes inherited from Metric
#errors, #result
Instance Method Summary
collapse
Methods inherited from Metric
all, #error, #initialize
Instance Method Details
#calculate_failure_rate ⇒ Object
10
11
12
13
14
15
|
# File 'lib/sidekiq_queue_status/failure_rate.rb', line 10
def calculate_failure_rate
stats = Sidekiq::Stats::History.new(1)
processed, failed = [stats.processed, stats.failed].map { |h| h.values.last }
val = (failed.to_f / processed.to_f) * 100.0
val > 0 ? val.to_i : 0
end
|
#max_failure_rate ⇒ Object
#monitor ⇒ Object
4
5
6
7
8
|
# File 'lib/sidekiq_queue_status/failure_rate.rb', line 4
def monitor
calculate_failure_rate.tap do |failure_rate|
error("Failure rate above #{max_failure_rate}%") if failure_rate > max_failure_rate
end
end
|