Skip to content

Commit

Permalink
fix: return threshold in status for zabbix
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskorobicyn committed Aug 22, 2016
1 parent 029459f commit e740ba0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/controllers/resque/queues/status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def show
age(params['queue'])
when 'size'
size(params['queue'])
when 'size_threshold'
Resque.queues_info.size_threshold(params.fetch('queue'))
when 'age_threshold'
Resque.queues_info.age_threshold(params.fetch('queue'))
else
0
end.to_s
Expand Down
20 changes: 12 additions & 8 deletions lib/resque/integration/queues_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def age_overall

return 0 if job.nil? || max_time.nil?

threshold = (@queues[job['queue']] || @defaults)['max_age']

max_time >= threshold ? max_time : 0
max_time >= age_threshold(job['queue']) ? max_time : 0
end

def size_for_queue(queue = nil)
Expand All @@ -34,17 +32,21 @@ def size_overall
[queue, Resque.size(queue).to_i]
end.max_by(&:last)

thresholds = (@queues[queue] || @defaults)['max_size']
size >= size_threshold(queue) ? size : 0
end

def size_threshold(queue)
(@queues[queue] || @defaults)['max_size']
end

size >= thresholds ? size : 0
def age_threshold(queue)
(@queues[queue] || @defaults)['max_age']
end

def data
@data ||= @queues.map do |k, v|
{
"{#QUEUE}" => k,
"{#THRESHOLD_AGE}" => v.fetch('max_age'),
"{#THRESHOLD_SIZE}" => v.fetch('max_size')
"{#QUEUE}" => k
}
end
end
Expand Down Expand Up @@ -81,6 +83,8 @@ def expand_config(config)
v = config.delete(key)

key.split(',').each do |queue|
queue.chomp!
queue.strip!
config[queue] = v
end
end
Expand Down
36 changes: 36 additions & 0 deletions spec/resque/integration/queues_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,40 @@
end
end
end

describe '#age_threshold' do
context 'when queue defined in config' do
let(:queue_name) { 'first' }

it 'returns threshold for age' do
expect(queue_info.age_threshold(queue_name)).to eq 20
end
end

context 'when queue not defined in config' do
let(:queue_name) { 'second' }

it 'returns default threshold' do
expect(queue_info.age_threshold(queue_name)).to eq 10
end
end
end

describe '#size_threshold' do
context 'when queue defined in config' do
let(:queue_name) { 'first' }

it 'returns threshold for size' do
expect(queue_info.size_threshold(queue_name)).to eq 100
end
end

context 'when queue not defined in config' do
let(:queue_name) { 'second' }

it 'returns default threshold' do
expect(queue_info.size_threshold(queue_name)).to eq 10
end
end
end
end

0 comments on commit e740ba0

Please sign in to comment.