-
Notifications
You must be signed in to change notification settings - Fork 7
/
cli.rb
executable file
·48 lines (41 loc) · 1.15 KB
/
cli.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
# cli.rb
# Brandon Burton, 2014
require 'rubygems'
require 'trollop'
require 'lib/status'
SUB_COMMANDS = %w(status consumer_lag)
global_opts = Trollop::options do
banner "Kafka Status Utility"
stop_on SUB_COMMANDS
end
cmd = ARGV.shift # get the subcommand
cmd_opts = case cmd
when "status"
Trollop::options do
opt :verbose, "Verbose output?", :required => false
next
end
when "consumer_lag"
Trollop::options do
opt :graphite_host, "Graphite Host to send metrics to", :required => true, :type => String
opt :environment, "The environment the script is running in", :required => true, :type => String
opt :verbose, "Verbose output?", :required => false
end
else
Trollop::die "Use status or consumer_lag"
end
# Where kafka lives
kafka_dir = "/opt/kafka"
$kafka_bin = "#{kafka_dir}/bin/"
$kafka_config = "#{kafka_dir}/config/server.properties"
if __FILE__ == $0
$verbose = cmd_opts[:verbose]
if cmd.inspect =~ /status/
kafka_status()
elsif cmd.inspect =~ /consumer_lag/
$graphite_host = cmd_opts[:graphite_host]
$environment = cmd_opts[:environment]
consumer_lag()
end
end