Class: SidekiqQueueStatus::FailureRate

Inherits:
Metric
  • Object
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

Constructor Details

This class inherits a constructor from SidekiqQueueStatus::Metric

Instance Method Details

#calculate_failure_rateObject



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_rateObject



17
18
19
# File 'lib/sidekiq_queue_status/failure_rate.rb', line 17

def max_failure_rate
  Metric.config['queue_failure_rate'] || DEFAULT_FAILURE_RATE_PERC
end

#monitorObject



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