Class: SidekiqQueueStatus::QueueLatency

Inherits:
Metric
  • Object
show all
Defined in:
lib/sidekiq_queue_status/queue_latency.rb

Constant Summary collapse

DEFAULT_TRESHOLD =
30

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

#max_latency(name) ⇒ Object



14
15
16
# File 'lib/sidekiq_queue_status/queue_latency.rb', line 14

def max_latency(name)
  Hash.new(DEFAULT_TRESHOLD).merge(Metric.config['queue_tresholds'])[name]
end

#monitorObject



4
5
6
7
8
# File 'lib/sidekiq_queue_status/queue_latency.rb', line 4

def monitor
  queues_with_latency.each do |name, latency|
    error("Queue #{name} above threshold of #{max_latency(name)}s") if latency > max_latency(name)
  end
end

#queues_with_latencyObject



10
11
12
# File 'lib/sidekiq_queue_status/queue_latency.rb', line 10

def queues_with_latency
  Hash[*Sidekiq::Queue.all.map { |q| [q.name, q.latency.to_i] }.flatten]
end