From b210988b674b0d0f939461c1be7f8eb36f0435aa Mon Sep 17 00:00:00 2001 From: Helder Ribeiro Date: Thu, 21 May 2009 22:34:44 +0200 Subject: [PATCH] Initial version --- plugins/other/delayed_jobs_queue_size | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 plugins/other/delayed_jobs_queue_size diff --git a/plugins/other/delayed_jobs_queue_size b/plugins/other/delayed_jobs_queue_size new file mode 100755 index 00000000..f253938a --- /dev/null +++ b/plugins/other/delayed_jobs_queue_size @@ -0,0 +1,58 @@ +#!/usr/bin/env ruby +# by Helder Ribeiro 2009 +# +# 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' +require 'yaml' + +class Grapher + + def initialize(db_conf) + @db_conf = db_conf + end + + def config + puts <<-END_CONFIG +graph_title Delayed_Jobs Queue Size +graph_args -l 0 +graph_vlabel jobs to be run +jobs.label jobs +jobs.type GAUGE + END_CONFIG + end + + def get_data + mysql = Mysql.new(@db_conf['host'] || 'localhost', + @db_conf['username'] || 'root', @db_conf['password'], + @db_conf['database'], @db_conf['port'], + @db_conf['socket']) + result = mysql.query("SELECT count(*) FROM delayed_jobs WHERE \ + first_started_at IS NULL OR run_at > NOW()") + value = result.fetch_hash.values.first + puts "jobs.value #{value}" + end + +end + +if __FILE__ == $0 + + environment = ENV['RAILS_ENV'] || 'production' + db_conf = YAML.load(File.read(ENV['DATABASE_YML']))[environment] + grapher = Grapher.new(db_conf) + + case ARGV.first + when 'config' + grapher.config + else + grapher.get_data + end + +end