8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/sidekiq_utils/latency_alert.rb', line 8
def check!
alerts = {}
Sidekiq::Queue.all.each do |queue|
threshold = config['alert_thresholds'][queue.name].
try!(&:to_i).try!(:minutes)
next if threshold == :disabled
threshold ||= config['alert_thresholds']['default'].
try!(&:to_i).try!(:minutes) || 10.minutes
if (latency = queue.latency) > threshold
alerts[queue.name] = latency
end
end
if alerts.blank?
if should_alert_back_to_normal?
Sidekiq.redis { |r| r.del(REDIS_KEY) }
slack_alert("All queues under their thresholds.")
end
return false
end
alert_message = ["Sidekiq queue latency over threshold:"]
alerts.each do |queue, latency|
alert_message << "Queue #{queue} is #{formatted_latency(latency)} behind"
end
alert_message = alert_message.join("\n")
if should_alert_again?(alert_message)
slack_alert(alert_message)
end
true
end
|