Skip to content

Instantly share code, notes, and snippets.

@heffergm
Created July 6, 2011 12:37
Show Gist options
  • Save heffergm/1067122 to your computer and use it in GitHub Desktop.
Save heffergm/1067122 to your computer and use it in GitHub Desktop.
Send resque queue data to Graphite
#!/usr/bin/env ruby
## Send resque queue depth data to Graphite
## Grant H - 6/1/11
require 'rubygems'
require 'resque'
## Read in our graphite host from file
graphite_host = File.read("/opt/scripts/bin/graphite_host")
loop do
queues = {}
time = Time.new
epoch = time.to_i
Resque.redis = "YOUR_REDIS_HOSTNAME:6379"
begin
Resque.queues.each do |queue|
queues[queue] = Resque.size(queue)
end
rescue
puts "error: #{$!}"
else
## Graphite host
begin
s = TCPSocket.open("#{graphite_host}", 2003)
rescue
puts "error: #{$!}"
else
## Send data
queues.each do |queue, depth|
s.write("stats.brewster.production.resque.#{queue} #{depth} #{epoch}\n")
end
s.close
end
end
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment