forked from cloudkick/agent-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resque
executable file
·58 lines (52 loc) · 1.71 KB
/
resque
1
2
3
4
5
6
7
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env ruby
# Cloudkick plugin for monitoring Resque <https://github.com/defunkt/resque>
#
# USAGE
#
# The script assume you're running Redis on localhost on the standard Redis
# port, 6379. To connect to a different host set the REDIS_URI environment
# variable.
#
# We don't actually install this script directly into the plugin folder.
# Instead, we keep it inside our app at script/cloudkick-resque. The actual
# plugin that the agent runs looks something like this:
#
# $ cat /usr/lib/cloudkick-agent/plugins/resque
# #!/bin/sh
# export REDIS_URI=ec2-50-16-42-174.compute-1.amazonaws.com:6379
# cd /data/app/current && bundle exec script/cloudkick-resque
#
# You can also specify the Redis URI via arguments:
# https://support.cloudkick.com/Creating_a_Plugin#Arguments
#
# AUTHOR Simon Rozet <https://github.com/sr>
# COPYING WTFPL <http://sam.zoy.org/wtfpl/>
require "resque"
if uri = ARGV.first
Resque.redis = uri
elsif uri = ENV["REDIS_URI"]
Resque.redis = uri
end
workers = Resque.workers
total = workers.size
idling = workers.select { |w| w.idle? }.size
working = Resque.working.reject { |w| w.idle? }.size
busyness = (working.to_f / total) * 100
info = Resque.info
failed = info[:failed]
processed = info[:processed]
queues = info[:queues]
if busyness == 100
puts "status err out of workers"
elsif busyness >= 60
puts "status err backed up #{idling}/#{total} free workers"
elsif busyness >= 40
puts "status warn #{idling}/#{total} free workers"
else
puts "status ok #{idling}/#{total} free workers"
end
puts "metric working int #{working}"
puts "metric idling int #{idling}"
puts "metric processed gauge #{processed}"
puts "metric failed gauge #{failed}"
puts "metric queues int #{queues}"