diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..767cddc --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2008 Dustin Sallings + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..fc50e7e --- /dev/null +++ b/README.markdown @@ -0,0 +1,22 @@ +# Beanstalk Utilities + +Here is a small collection of tools for watching, monitoring, and +manipulating beanstalkd. + +## Interactive Commands + +Interactive commands are in the bin directory. + +### beanstalk-stats.rb + +beanstalk-stats.rb gives you a feel for how fast things are going in and out +of your queue. + + usage: beanstalk-stats.rb host:11300 host2:11300 [...] + +### beanstalk-queue-stats.rb + +beanstalk-queue-stats.rb watches a single beanstalk instance and shows you +which tubes contain elements, and how fast they're changing. + + usage: beanstalk-queue-stats.rb host:11300 diff --git a/bin/beanstalk-queue-stats.rb b/bin/beanstalk-queue-stats.rb new file mode 100755 index 0000000..c5185c1 --- /dev/null +++ b/bin/beanstalk-queue-stats.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby + +require 'rubygems' +require 'beanstalk-client' + +B = Beanstalk::Connection.new $*[0] + +tubes = $*[1..-1] +tubes = B.list_tubes if tubes.empty? + +def delta(v) + v.to_i > 0 ? "+#{v}" : v.to_s +end + +previously={} + +loop do + puts "#{Time.now.to_s}" + tubes.each do |tube| + puts "#{tube}" + ts=B.stats_tube tube + ts.delete('name') + deltas = previously[tube] || Hash.new(0) + ts.keys.sort.each do |k| + puts " - #{k} = #{ts[k]} (#{delta(ts[k] - deltas[k])})" + end + previously[tube] = ts + end + puts "------------------" + sleep 10 +end diff --git a/bin/beanstalk-stats.rb b/bin/beanstalk-stats.rb new file mode 100755 index 0000000..bd9f227 --- /dev/null +++ b/bin/beanstalk-stats.rb @@ -0,0 +1,43 @@ +#!/usr/bin/env ruby + +require 'rubygems' +require 'beanstalk-client' + +def delta(ov, nv) + sym = nv > ov ? "+" : "" + fmt = nil + if ov.is_a?(Fixnum) + fmt = "(%s%d)" + elsif ov.is_a?(Float) + fmt = "(%s%.4f)" + else + nil + end + + if fmt + sprintf fmt, sym, (nv - ov) + end +end + +def show_stats(oldstats, bp) + s = bp.stats + puts "----------- #{Time.now} -----------" + s.keys.sort.each do |k| + if oldstats[k] + if oldstats[k] != s[k] + puts "#{k} = #{s[k]} #{delta oldstats[k], s[k]}" + end + else + puts "#{k} = #{s[k]}" + end + end + s +end + +bp = Beanstalk::Pool.new $* +oldstats = {} + +loop do + oldstats = show_stats(oldstats, bp) + sleep 10 +end