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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/cawcaw/command/rabbitmq/queue_count.rb', line 4
def self.run(argv, input_stream=$stdin, output_stream=$stdout)
params = Cawcaw.parse_opts(argv)
params.update(Bunnish.parse_opts(argv))
params[:graph_title] ||= "Queue count"
params[:graph_args] ||= "--base 1000"
params[:graph_vlabel] ||= "messages"
params[:graph_category] ||= "rabbitmq"
params[:graph_info] ||= "Queue count"
params[:label_warning] ||= 5000000
params[:label_critical] ||= 5000000
host = params[:host]
port = params[:port]
user = params[:user]
password = params[:password]
durable = params[:durable]
if params[:stdin_flag]
queue_names = []
while line = input_stream.gets
line.chomp!
queue_names.push line
end
else
queue_names = argv.shift
queue_names = queue_names.split(/,/) unless queue_names.nil?
queue_names ||= []
queue_names.delete("")
end
command = argv.shift
if queue_names == []
Cawcaw.logger.error("queue-name is not set")
return 1
end
case command
when "autoconf"
output_stream.puts "yes"
when "config"
output_stream.puts "graph_title \#{params[:graph_title]}\ngraph_args \#{params[:graph_args]}\ngraph_vlabel \#{params[:graph_vlabel]}\ngraph_category \#{params[:graph_category]}\ngraph_info \#{params[:graph_info]}\n EOF\n \n label_draw = \"AREA\"\n \n queue_names.each do |queue_name|\n label = queue_name.gsub(/[^a-zA-Z0-9]/, \"_\").downcase\n output_stream.puts <<-EOF\n\#{label}.label \#{queue_name}\n\#{label}.info \#{queue_name} queue count\n\#{label}.draw \#{label_draw}\n\#{label}.warning \#{params[:label_warning]}\n\#{label}.critical \#{params[:label_critical]}\n EOF\n label_draw = \"STACK\"\n end\n else\n bunny = Bunny.new(:logging => false, :spec => '09', :host=>host, :port=>port, :user=>user, :pass=>password)\n \n # start a communication session with the amqp server\n bunny.start\n \n queue_message_counts = bunny.queue_message_counts(queue_names, :durable=>durable)\n \n queue_message_counts.each_pair do |queue_name, message_count|\n label = queue_name.gsub(/[^a-zA-Z0-9]/, \"_\").downcase\n output_stream.puts \"\#{label}.value \#{message_count}\"\n end\n # Close client\n bunny.stop\n \n end\n \n return 0\nend\n"
|