Class: SidekiqVigil::Check::FailureRate

Inherits:
Base
  • Object
show all
Defined in:
lib/sidekiq_vigil/check/failure_rate.rb

Instance Attribute Summary

Attributes inherited from Base

#api, #clock, #logger, #options, #storage

Instance Method Summary collapse

Methods inherited from Base

#check_name, #execute, #initialize

Constructor Details

This class inherits a constructor from SidekiqVigil::Check::Base

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sidekiq_vigil/check/failure_rate.rb', line 6

def call
  processed, failed = counts
  rate = processed.zero? ? 0.0 : failed.fdiv(processed)
  return insufficient_samples(processed, rate) if processed < options.fetch(:min_samples, 20)

  threshold_result(
    target: "global",
    value: rate,
    warn: options.fetch(:warn, 0.05),
    critical: options.fetch(:critical, 0.20),
    message: format("%<rate>.1f%% failures (%<failed>d/%<processed>d attempts)", rate: rate * 100, failed:, processed:),
    metadata: { processed:, failed: }
  )
end