Class: SidekiqInsight::LeakDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_insight/leak_detector.rb

Instance Method Summary collapse

Constructor Details

#initialize(storage:) ⇒ LeakDetector

Returns a new instance of LeakDetector.



3
4
5
# File 'lib/sidekiq_insight/leak_detector.rb', line 3

def initialize(storage:)
  @storage = storage
end

Instance Method Details

#detect(key, window = 20) ⇒ Object

check last N samples for rising memory trend



8
9
10
11
# File 'lib/sidekiq_insight/leak_detector.rb', line 8

def detect(key, window = 20)
  samples = @storage.recent(key, window)
  SidekiqInsight::Metrics.detect_leak(samples)
end

#recent_alerts(limit = 20) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/sidekiq_insight/leak_detector.rb', line 13

def recent_alerts(limit = 20)
  jobs = @storage.top_jobs(100)
  alerts = []
  jobs.each do |j|
    leak = detect(j[:key], 50)
    alerts << { job: j[:key], leak: leak } if leak
    break if alerts.size >= limit
  end
  alerts
end