Skip to content

Instantly share code, notes, and snippets.

@viniciusdaniel
Created May 4, 2012 23:06
Show Gist options
  • Save viniciusdaniel/2598254 to your computer and use it in GitHub Desktop.
Save viniciusdaniel/2598254 to your computer and use it in GitHub Desktop.
munin plugin for show resque workers
#!/usr/bin/env ruby
# Description: Show number of workers by server based on "https://gist.github.com/1334470"
# Source: https://gist.github.com/2598254
#
require 'rubygems'
require 'resque'
HOST = ENV['host'] ? ENV['host'] : '127.0.0.1'
PORT = ENV['port'] ? ENV['port'] : '6379'
Resque.redis = "#{HOST}:#{PORT}"
servers = {}
Resque.workers.map { |w| w.to_s.split(':').first }.uniq.each { |s| servers[s] = 0 }
if ARGV.any? && ARGV[0] == 'config'
puts 'graph_title Workers by Servers'
puts 'graph_vlabel Workers'
puts 'graph_category resque'
servers.keys.each do |server|
puts "#{server.gsub(/\W/,'_')}.label #{server}"
end
exit 0
end
Resque.workers.map{ |w| w.to_s.split(':').first }.each do |s|
servers[s] += 1
end
servers.each_pair{ |server, workers|
puts "#{server.gsub(/\W/,'_')}.value #{workers}"
}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment