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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/cawcaw/command/database/table.rb', line 37
def run(argv, input_stream=$stdin, output_stream=$stdout)
params = Cawcaw.parse_opts(argv)
self.initialize_params(params)
bytes_flag = (params[:graph_vlabel] == "bytes")
if params[:stdin_flag]
table_paths = []
while line = input_stream.gets
line.chomp!
table_paths.push line
end
else
table_paths = argv.shift
table_paths = table_paths.split(/,/) unless table_paths.nil?
table_paths ||= []
table_paths.delete("")
end
command = argv.shift
if table_paths == []
Cawcaw.logger.error("#{params[:adapter]} table name is not set")
return 1
end
case command
when "autoconf"
output_stream.puts "yes"
when "config"
output_stream.puts <<-EOF
graph_title #{params[:graph_title]}
graph_args #{params[:graph_args]}
graph_vlabel #{params[:graph_vlabel]}
graph_category #{params[:graph_category]}
graph_info #{params[:graph_info]}
EOF
label_draw = "AREA"
table_paths.each do |table_path|
label = table_path.gsub(/[^a-zA-Z0-9]/, "_").downcase
output_stream.puts <<-EOF
#{label}.label #{table_path}
#{label}.info #{table_path} size
#{label}.draw #{label_draw}
EOF
output_stream.puts "#{label}.warning #{params[:label_warning]}" if params[:label_warning]
output_stream.puts "#{label}.critical #{params[:label_critical]}" if params[:label_critical]
label_draw = "STACK"
end
else
full_table_paths = self.get_full_table_paths(table_paths, params)
return 1 if full_table_paths.nil?
results = self.count_table_sizes(table_paths.map{|t|full_table_paths[t]}, params)
table_sizes = {}
results.each do |record|
table_path = record[0] || record["full_table_path"]
if bytes_flag
table_sizes[table_path] = (record[2] || record["byte_size"]).to_i
else
table_sizes[table_path] = (record[1] || record["record_size"]).to_i
end
end
table_paths.each do |table_path|
label = table_path.gsub(/[^a-zA-Z0-9]/, "_").downcase
table_size = table_sizes[full_table_paths[table_path]]
output_stream.puts "#{label}.value #{table_size}"
end
end
return 0
end
|