Skip to content

Commit

Permalink
Initial checkin of beanstalk tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Sep 14, 2008
0 parents commit a92621a
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,19 @@
Copyright (c) 2008 Dustin Sallings <dustin@spy.net>

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.
22 changes: 22 additions & 0 deletions 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
31 changes: 31 additions & 0 deletions 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
43 changes: 43 additions & 0 deletions 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

0 comments on commit a92621a

Please sign in to comment.