Skip to content

Commit ecca61a

Browse files
author
Robey Pointer
committed
move kcluster into its own folder and give it a full gem layout like it had before. switch to the json interface of colony.
1 parent 5e3ff48 commit ecca61a

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ target
22
kestrel.tmproj
33
dist
44
*.class
5-
bin
65
.manager
76
.DS_Store
87
*.sw?
@@ -19,3 +18,5 @@ ignore/
1918
.scala_dependencies
2019
.settings/
2120
go
21+
kestrel.sublime-*
22+
kcluster-*.gem

src/main/ruby/kcluster/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.1.0

src/scripts/kcluster src/main/ruby/kcluster/bin/kcluster

+37-14
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,44 @@
33
$:.push(File.dirname($0))
44
require 'optparse'
55
require 'socket'
6+
require 'net/http'
7+
require 'json'
8+
9+
# FIXME this really only works inside twitter. it would be nice to support
10+
# a general serverset interface (or opensource colony).
11+
$colony_host = ENV["COLONY_HOST"] || "colony.smf1.twitter.com"
12+
$colony_port = ENV["COLONY_PORT"] || 9080
613

714
$options = {
815
:config_filename => ENV['HOME'] + "/.kestrel_cluster",
916
:server_list => [],
1017
:port => 22133,
18+
:verbose => false,
1119
}
1220

21+
def verbose(s)
22+
puts s if $options[:verbose]
23+
end
24+
1325
def fetch_stats(host, port, data)
14-
puts "--- Fetching stats from #{host}:#{port}"
26+
verbose "--- Fetching stats from #{host}:#{port}"
1527
sock = TCPSocket.open(host, port)
1628
sock.puts("stats")
1729
done = false
1830
while !done && line = sock.gets.chomp
1931
if (line == 'END') then
2032
done = true
21-
elsif line =~ /STAT queue_([\w+]+) (\d+)/
33+
elsif line =~ /STAT queue_([\w\+\-]+) (\d+)/
2234
key = $1
2335
value = $2.to_i
2436
(stat, queue_name) = case key
25-
when /([\w+]+)_total_items/ then [:total_items, $1]
26-
when /([\w+]+)_expired_items/ then [:expired_items, $1]
27-
when /([\w+]+)_mem_items/ then [:mem_items, $1]
28-
when /([\w+]+)_items/ then [:items, $1]
29-
when /([\w+]+)_mem_bytes/ then [:mem_bytes, $1]
30-
when /([\w+]+)_bytes/ then [:bytes, $1]
31-
when /([\w+]+)_age/ then [:age, $1]
37+
when /([\w\+\-]+)_total_items/ then [:total_items, $1]
38+
when /([\w\+\-]+)_expired_items/ then [:expired_items, $1]
39+
when /([\w\+\-]+)_mem_items/ then [:mem_items, $1]
40+
when /([\w\+\-]+)_items/ then [:items, $1]
41+
when /([\w\+\-]+)_mem_bytes/ then [:mem_bytes, $1]
42+
when /([\w\+\-]+)_bytes/ then [:bytes, $1]
43+
when /([\w\+\-]+)_age/ then [:age, $1]
3244
end
3345

3446
if (queue_name)
@@ -151,15 +163,21 @@ end
151163

152164
parser = OptionParser.new do |opts|
153165
opts.banner = "Usage: #{$0} [options] <command>"
154-
opts.separator "Example: #{$0} -f shards.yml 11"
166+
opts.separator "Example: #{$0} -f kestrel max_age"
155167

156168
opts.on("-f", "--file=FILENAME", "load kestrel server list from file (use '-' for stdin) (default: #{$options[:config_filename]})") do |filename|
157169
$options[:config_filename] = filename
158170
end
159171
opts.on("-p", "--port=N", "use port (default: #{$options[:port]})") do |port|
160172
$options[:port] = port.to_i
161173
end
162-
opts.on("-r", "--rollup-fanouts", "roll up stats for fanout queues into a single count") do
174+
opts.on("-r", "--role=ROLE", "load kestrel server list from colony audubon role (requires colony)") do |role|
175+
$options[:role] = role
176+
end
177+
opts.on("-v", "--verbose", "print verbose debugging info as we work") do
178+
$options[:verbose] = true
179+
end
180+
opts.on("-F", "--rollup-fanouts", "roll up stats for fanout queues into a single count") do
163181
$options[:rollup_fanouts] = true
164182
end
165183

@@ -186,9 +204,14 @@ if ARGV.size < 1
186204
exit 1
187205
end
188206

189-
server_file = $options[:config_filename] == "-" ? STDIN : File.open($options[:config_filename], "r")
190-
$options[:server_list] = server_file.readlines.map { |line| line.chomp }
191-
server_file.close
207+
if $options[:role]
208+
data = Net::HTTP.get URI.parse("http://#{$colony_host}:#{$colony_port}/query?q=mo+audubon.role.#{$options[:role]}")
209+
$options[:server_list] = JSON.parse(data).values.flatten
210+
else
211+
server_file = $options[:config_filename] == "-" ? STDIN : File.open($options[:config_filename], "r")
212+
$options[:server_list] = server_file.readlines.map { |line| line.chomp }
213+
server_file.close
214+
end
192215

193216
command = ARGV[0].downcase
194217

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Gem::Specification.new do |s|
2+
s.name = "kcluster"
3+
s.version = File.open("VERSION").read.chomp
4+
5+
s.authors = ["Robey Pointer"]
6+
s.email = "[email protected]"
7+
s.homepage = "http://robey.github.com/kestrel"
8+
s.summary = "Kestrel cluster management tool"
9+
s.description = """\
10+
A handy little CLI tool for browsing quick stats across your kestrel cluster.
11+
Kcluster collects stats from each machine in a cluster, then summarizes them
12+
into one table.
13+
"""
14+
15+
s.files = Dir.glob("lib/**/*.rb") + [ 'bin/kcluster' ]
16+
s.require_paths = [ "lib" ]
17+
s.executables = [ "kcluster" ]
18+
19+
s.add_dependency 'json'#, '~> 1.0.0'
20+
end

src/main/ruby/kcluster/lib/nothing.rb

Whitespace-only changes.

0 commit comments

Comments
 (0)