Created
August 26, 2010 14:47
-
-
Save jakimowicz/551520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# by Helder Ribeiro 2009 | |
# by Fabien Jakimowicz 2010 | |
# | |
# Plugin to monitor delayed_jobs' queue size | |
# Gives updates with number of jobs that haven't been started yet | |
# plus the ones that failed and are still rescheduled for another run | |
# | |
# Parameters supported: | |
# | |
# config | |
require 'rubygems' | |
require 'mysql' | |
class Grapher | |
def config | |
puts <<-END_CONFIG | |
graph_category Delayed Jobs | |
graph_title Delayed_Jobs Queue Size | |
graph_args -l 0 | |
graph_vlabel jobs to be run | |
clean.label jobs | |
clean.type GAUGE | |
clean.info New and clean jobs to run. | |
retry.label retry | |
retry.type GAUGE | |
retry.info Failed jobs that are postponed for a later retry. | |
END_CONFIG | |
end | |
def get_data | |
mysql = Mysql.new(ENV['hostname'] || 'localhost', | |
ENV['username'] || 'root', ENV['password'], | |
ENV['database'], nil, nil) | |
result = mysql.query("SELECT count(*) FROM delayed_jobs WHERE \ | |
locked_at IS NULL AND failed_at IS NULL \ | |
AND attempts = 0") | |
puts "clean.value #{result.fetch_hash.values.first}" | |
result = mysql.query("SELECT count(*) FROM delayed_jobs WHERE \ | |
locked_at IS NULL AND failed_at IS NULL \ | |
AND attempts > 0") | |
puts "retry.value #{result.fetch_hash.values.first}" | |
end | |
end | |
if __FILE__ == $0 | |
grapher = Grapher.new | |
case ARGV.first | |
when 'config' | |
grapher.config | |
else | |
grapher.get_data | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment