cawcaw 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/README.md +12 -3
- data/VERSION +1 -1
- data/bin/cawcaw +2 -0
- data/cawcaw.gemspec +13 -8
- data/lib/cawcaw.rb +2 -0
- data/lib/cawcaw/command/database.rb +17 -0
- data/lib/cawcaw/command/database/table.rb +122 -0
- data/lib/cawcaw/command/mysql.rb +17 -0
- data/lib/cawcaw/command/mysql/table.rb +25 -0
- data/lib/cawcaw/command/postgresql/table.rb +41 -106
- data/spec/bin/cawcaw/mysql/table_spec.rb +51 -0
- data/spec/bin/cawcaw/postgresql/table_spec.rb +22 -5
- metadata +189 -172
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -17,11 +17,20 @@ You can install cawcaw by gem.
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
-
### Draw munin graph of
|
21
|
-
cawcaw
|
20
|
+
### Draw munin graph of MySQL table record size
|
21
|
+
cawcaw mysql table [--host host] [--port port]
|
22
|
+
[--username username] [--password password]
|
23
|
+
[--database database] [--encoding encoding]
|
24
|
+
table <table-name[,table-name...]> [autoconf|config]
|
22
25
|
|
23
26
|
### Draw munin graph of PostgreSQL table record size
|
24
|
-
cawcaw postgresql table
|
27
|
+
cawcaw postgresql table [--host host] [--port port]
|
28
|
+
[--username username] [--password password]
|
29
|
+
[--database database] [--encoding encoding]
|
30
|
+
table <table-name[,table-name...]> [autoconf|config]
|
31
|
+
|
32
|
+
### Draw munin graph of Hadoop HDFS size
|
33
|
+
cawcaw hadoop dfs <hdfs-path[,hdfs-path...]> [autoconf|config]
|
25
34
|
|
26
35
|
### Draw munin graph of RabbitMQ queue message count
|
27
36
|
cawcaw rabbitmq queue-count <queue-name[,queue-name...]> [autoconf|config]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/cawcaw
CHANGED
data/cawcaw.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "cawcaw"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kenji Hara"]
|
12
|
-
s.date = "2013-01-
|
12
|
+
s.date = "2013-01-21"
|
13
13
|
s.description = "cawcaw RubyGem"
|
14
14
|
s.email = "haracane@gmail.com"
|
15
15
|
s.executables = ["cawcaw"]
|
@@ -28,14 +28,19 @@ Gem::Specification.new do |s|
|
|
28
28
|
"bin/cawcaw",
|
29
29
|
"cawcaw.gemspec",
|
30
30
|
"lib/cawcaw.rb",
|
31
|
+
"lib/cawcaw/command/database.rb",
|
32
|
+
"lib/cawcaw/command/database/table.rb",
|
31
33
|
"lib/cawcaw/command/hadoop.rb",
|
32
34
|
"lib/cawcaw/command/hadoop/dfs.rb",
|
35
|
+
"lib/cawcaw/command/mysql.rb",
|
36
|
+
"lib/cawcaw/command/mysql/table.rb",
|
33
37
|
"lib/cawcaw/command/postgresql.rb",
|
34
38
|
"lib/cawcaw/command/postgresql/table.rb",
|
35
39
|
"lib/cawcaw/command/rabbitmq.rb",
|
36
40
|
"lib/cawcaw/command/rabbitmq/queue_count.rb",
|
37
41
|
"lib/cawcaw/core/common.rb",
|
38
42
|
"spec/bin/cawcaw/hadoop/dfs_spec.rb",
|
43
|
+
"spec/bin/cawcaw/mysql/table_spec.rb",
|
39
44
|
"spec/bin/cawcaw/postgresql/table_spec.rb",
|
40
45
|
"spec/bin/cawcaw/rabbitmq/queue_count_spec.rb",
|
41
46
|
"spec/lib/cawcaw_spec.rb",
|
@@ -52,6 +57,7 @@ Gem::Specification.new do |s|
|
|
52
57
|
|
53
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
59
|
s.add_runtime_dependency(%q<activerecord>, ["~> 3.2.11"])
|
60
|
+
s.add_runtime_dependency(%q<mysql2>, ["~> 0.3.11"])
|
55
61
|
s.add_runtime_dependency(%q<activerecord-postgresql-adapter>, ["~> 0.0.1"])
|
56
62
|
s.add_runtime_dependency(%q<bunnish>, ["~> 0.1.2"])
|
57
63
|
s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
|
@@ -60,12 +66,12 @@ Gem::Specification.new do |s|
|
|
60
66
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
61
67
|
s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
|
62
68
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
63
|
-
s.add_development_dependency(%q<
|
64
|
-
s.add_development_dependency(%q<simplecov-rcov>, ["~> 0.2.3"])
|
69
|
+
s.add_development_dependency(%q<rcov>, ["~> 1.0.0"])
|
65
70
|
s.add_development_dependency(%q<ci_reporter>, ["~> 1.8.3"])
|
66
71
|
s.add_development_dependency(%q<flog>, [">= 3.2.0"])
|
67
72
|
else
|
68
73
|
s.add_dependency(%q<activerecord>, ["~> 3.2.11"])
|
74
|
+
s.add_dependency(%q<mysql2>, ["~> 0.3.11"])
|
69
75
|
s.add_dependency(%q<activerecord-postgresql-adapter>, ["~> 0.0.1"])
|
70
76
|
s.add_dependency(%q<bunnish>, ["~> 0.1.2"])
|
71
77
|
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
@@ -74,13 +80,13 @@ Gem::Specification.new do |s|
|
|
74
80
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
75
81
|
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
76
82
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
77
|
-
s.add_dependency(%q<
|
78
|
-
s.add_dependency(%q<simplecov-rcov>, ["~> 0.2.3"])
|
83
|
+
s.add_dependency(%q<rcov>, ["~> 1.0.0"])
|
79
84
|
s.add_dependency(%q<ci_reporter>, ["~> 1.8.3"])
|
80
85
|
s.add_dependency(%q<flog>, [">= 3.2.0"])
|
81
86
|
end
|
82
87
|
else
|
83
88
|
s.add_dependency(%q<activerecord>, ["~> 3.2.11"])
|
89
|
+
s.add_dependency(%q<mysql2>, ["~> 0.3.11"])
|
84
90
|
s.add_dependency(%q<activerecord-postgresql-adapter>, ["~> 0.0.1"])
|
85
91
|
s.add_dependency(%q<bunnish>, ["~> 0.1.2"])
|
86
92
|
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
@@ -89,8 +95,7 @@ Gem::Specification.new do |s|
|
|
89
95
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
90
96
|
s.add_dependency(%q<bundler>, ["~> 1.2.3"])
|
91
97
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
92
|
-
s.add_dependency(%q<
|
93
|
-
s.add_dependency(%q<simplecov-rcov>, ["~> 0.2.3"])
|
98
|
+
s.add_dependency(%q<rcov>, ["~> 1.0.0"])
|
94
99
|
s.add_dependency(%q<ci_reporter>, ["~> 1.8.3"])
|
95
100
|
s.add_dependency(%q<flog>, [">= 3.2.0"])
|
96
101
|
end
|
data/lib/cawcaw.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Cawcaw
|
2
|
+
module Command
|
3
|
+
module Database
|
4
|
+
def self.run(argv, input_stream=$stdin, output_stream=$stdout)
|
5
|
+
command = argv.shift
|
6
|
+
case command
|
7
|
+
when "table"
|
8
|
+
return Cawcaw::Command::Database::Table.run(argv, input_stream, output_stream)
|
9
|
+
else
|
10
|
+
STDERR.puts "invalid active-record command: '#{command}'"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require "cawcaw/command/database/table"
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Cawcaw
|
2
|
+
module Command
|
3
|
+
module Database
|
4
|
+
module Table
|
5
|
+
module ClassMethods
|
6
|
+
def initialize_params(params)
|
7
|
+
params[:host] ||= "localhost"
|
8
|
+
params[:adapter_name] ||= params[:adapter]
|
9
|
+
|
10
|
+
params[:graph_title] ||= "#{params[:adapter_name]} Records"
|
11
|
+
params[:graph_args] ||= "--base 1000"
|
12
|
+
params[:graph_vlabel] ||= "records"
|
13
|
+
params[:graph_category] ||= params[:adapter_name]
|
14
|
+
params[:graph_info] ||= "#{params[:adapter_name]} record size"
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_full_table_paths(table_paths, params)
|
18
|
+
full_table_paths = {}
|
19
|
+
table_paths.each do |table_path|
|
20
|
+
full_table_paths[table_path] = table_path
|
21
|
+
end
|
22
|
+
return full_table_paths
|
23
|
+
end
|
24
|
+
|
25
|
+
def count_table_sizes(full_table_paths, params)
|
26
|
+
ActiveRecord::Base.establish_connection(params)
|
27
|
+
count_sql = <<-EOF
|
28
|
+
#{
|
29
|
+
full_table_paths.map{|full_table_path|
|
30
|
+
"(select #{ActiveRecord::Base.sanitize(full_table_path)} as full_table_path, count(*) as record_size from #{full_table_path})"
|
31
|
+
}.join(" union ")
|
32
|
+
}
|
33
|
+
EOF
|
34
|
+
results = ActiveRecord::Base.connection.execute count_sql
|
35
|
+
end
|
36
|
+
|
37
|
+
def run(argv, input_stream=$stdin, output_stream=$stdout)
|
38
|
+
|
39
|
+
params = Cawcaw.parse_opts(argv)
|
40
|
+
self.initialize_params(params)
|
41
|
+
bytes_flag = (params[:graph_vlabel] == "bytes")
|
42
|
+
|
43
|
+
if params[:stdin_flag]
|
44
|
+
table_paths = []
|
45
|
+
while line = input_stream.gets
|
46
|
+
line.chomp!
|
47
|
+
table_paths.push line
|
48
|
+
end
|
49
|
+
else
|
50
|
+
table_paths = argv.shift
|
51
|
+
table_paths = table_paths.split(/,/) unless table_paths.nil?
|
52
|
+
table_paths ||= []
|
53
|
+
table_paths.delete("")
|
54
|
+
end
|
55
|
+
command = argv.shift
|
56
|
+
|
57
|
+
if table_paths == []
|
58
|
+
Cawcaw.logger.error("#{params[:adapter]} table name is not set")
|
59
|
+
return 1
|
60
|
+
end
|
61
|
+
|
62
|
+
case command
|
63
|
+
when "autoconf"
|
64
|
+
output_stream.puts "yes"
|
65
|
+
when "config"
|
66
|
+
output_stream.puts <<-EOF
|
67
|
+
graph_title #{params[:graph_title]}
|
68
|
+
graph_args #{params[:graph_args]}
|
69
|
+
graph_vlabel #{params[:graph_vlabel]}
|
70
|
+
graph_category #{params[:graph_category]}
|
71
|
+
graph_info #{params[:graph_info]}
|
72
|
+
EOF
|
73
|
+
|
74
|
+
label_draw = "AREA"
|
75
|
+
|
76
|
+
table_paths.each do |table_path|
|
77
|
+
label = table_path.gsub(/[^a-zA-Z0-9]/, "_").downcase
|
78
|
+
output_stream.puts <<-EOF
|
79
|
+
#{label}.label #{table_path}
|
80
|
+
#{label}.info #{table_path} size
|
81
|
+
#{label}.draw #{label_draw}
|
82
|
+
EOF
|
83
|
+
output_stream.puts "#{label}.warning #{params[:label_warning]}" if params[:label_warning]
|
84
|
+
output_stream.puts "#{label}.critical #{params[:label_critical]}" if params[:label_critical]
|
85
|
+
label_draw = "STACK"
|
86
|
+
end
|
87
|
+
else
|
88
|
+
|
89
|
+
full_table_paths = self.get_full_table_paths(table_paths, params)
|
90
|
+
return 1 if full_table_paths.nil?
|
91
|
+
|
92
|
+
results = self.count_table_sizes(table_paths.map{|t|full_table_paths[t]}, params)
|
93
|
+
|
94
|
+
table_sizes = {}
|
95
|
+
results.each do |record|
|
96
|
+
table_path = record[0] || record["full_table_path"]
|
97
|
+
if bytes_flag
|
98
|
+
table_sizes[table_path] = (record[2] || record["byte_size"]).to_i
|
99
|
+
else
|
100
|
+
table_sizes[table_path] = (record[1] || record["record_size"]).to_i
|
101
|
+
end
|
102
|
+
end
|
103
|
+
table_paths.each do |table_path|
|
104
|
+
label = table_path.gsub(/[^a-zA-Z0-9]/, "_").downcase
|
105
|
+
table_size = table_sizes[full_table_paths[table_path]]
|
106
|
+
output_stream.puts "#{label}.value #{table_size}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
return 0
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
extend ClassMethods
|
115
|
+
|
116
|
+
def self.included(klass)
|
117
|
+
klass.extend ClassMethods
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Cawcaw
|
2
|
+
module Command
|
3
|
+
module Mysql
|
4
|
+
def self.run(argv, input_stream=$stdin, output_stream=$stdout)
|
5
|
+
command = argv.shift
|
6
|
+
case command
|
7
|
+
when "table"
|
8
|
+
return Cawcaw::Command::Mysql::Table.run(argv, input_stream, output_stream)
|
9
|
+
else
|
10
|
+
STDERR.puts "invalid postgresql command: '#{command}'"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require "cawcaw/command/mysql/table"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cawcaw
|
2
|
+
module Command
|
3
|
+
module Mysql
|
4
|
+
module Table
|
5
|
+
include Cawcaw::Command::Database::Table
|
6
|
+
|
7
|
+
def self.initialize_params(params)
|
8
|
+
params[:adapter] ||= "mysql2"
|
9
|
+
params[:host] ||= "localhost"
|
10
|
+
params[:port] ||= 3306
|
11
|
+
params[:adapter_name] ||= "mysql"
|
12
|
+
|
13
|
+
params[:graph_title] ||= "#{params[:adapter_name]} records"
|
14
|
+
params[:graph_args] ||= "--base 1000"
|
15
|
+
params[:graph_vlabel] ||= "records"
|
16
|
+
params[:graph_category] ||= params[:adapter_name]
|
17
|
+
params[:graph_info] ||= "#{params[:adapter_name]} record size"
|
18
|
+
|
19
|
+
params[:label_warning] ||= 50000000
|
20
|
+
params[:label_critical] ||= 100000000
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -2,131 +2,66 @@ module Cawcaw
|
|
2
2
|
module Command
|
3
3
|
module Postgresql
|
4
4
|
module Table
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
params[:graph_title] ||= "PostgreSQL Records"
|
10
|
-
params[:graph_args] ||= "--base 1000"
|
11
|
-
params[:graph_vlabel] ||= "records"
|
12
|
-
params[:graph_category] ||= "postgresql"
|
13
|
-
params[:graph_info] ||= "PostgreSQL record size"
|
14
|
-
|
15
|
-
bytes_flag = (params[:graph_vlabel] == "bytes")
|
16
|
-
|
17
|
-
params[:adapter] = "postgresql"
|
5
|
+
include Cawcaw::Command::Database::Table
|
6
|
+
|
7
|
+
def self.initialize_params(params)
|
8
|
+
params[:adapter] ||= "postgresql"
|
18
9
|
params[:host] ||= "localhost"
|
19
10
|
params[:port] ||= 5432
|
11
|
+
params[:adapter_name] ||= params[:adapter]
|
20
12
|
|
21
|
-
params[:
|
22
|
-
params[:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
params[:graph_title] ||= "#{params[:adapter_name]} records"
|
14
|
+
params[:graph_args] ||= "--base 1000"
|
15
|
+
params[:graph_vlabel] ||= "records"
|
16
|
+
params[:graph_category] ||= params[:adapter_name]
|
17
|
+
params[:graph_info] ||= "#{params[:adapter_name]} record size"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.get_full_table_paths(table_paths, params)
|
21
|
+
full_table_paths = {}
|
22
|
+
table_paths.each do |table_path|
|
23
|
+
table_path_pair = table_path.split(/\./)
|
24
|
+
if /[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)?/ !~ table_path
|
25
|
+
Cawcaw.logger.error("#{params[:adapter_name]} table name '#{table_path}' is invalid")
|
26
|
+
return nil
|
29
27
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
table_paths ||= []
|
34
|
-
table_paths.delete("")
|
35
|
-
end
|
36
|
-
command = argv.shift
|
37
|
-
|
38
|
-
if table_paths == []
|
39
|
-
Cawcaw.logger.error("PostgreSQL table name is not set")
|
40
|
-
return 1
|
28
|
+
table_name = table_path_pair.pop
|
29
|
+
schema_name = table_path_pair.pop || "public"
|
30
|
+
full_table_paths[table_path] = "#{schema_name}.#{table_name}"
|
41
31
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
graph_category #{params[:graph_category]}
|
52
|
-
graph_info #{params[:graph_info]}
|
53
|
-
EOF
|
54
|
-
|
55
|
-
label_draw = "AREA"
|
56
|
-
|
57
|
-
table_paths.each do |table_path|
|
58
|
-
label = table_path.gsub(/[^a-zA-Z0-9]/, "_").downcase
|
59
|
-
output_stream.puts <<-EOF
|
60
|
-
#{label}.label #{table_path}
|
61
|
-
#{label}.info #{table_path} size
|
62
|
-
#{label}.draw #{label_draw}
|
63
|
-
#{label}.warning #{params[:label_warning]}
|
64
|
-
#{label}.critical #{params[:label_critical]}
|
65
|
-
EOF
|
66
|
-
label_draw = "STACK"
|
67
|
-
end
|
68
|
-
else
|
69
|
-
|
70
|
-
ActiveRecord::Base.establish_connection(params)
|
71
|
-
|
72
|
-
full_table_paths = {}
|
73
|
-
table_paths.each do |table_path|
|
74
|
-
table_path_pair = table_path.split(/\./)
|
75
|
-
if /[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)?/ !~ table_path
|
76
|
-
Cawcaw.logger.error("PostgreSQL table name '#{table_path}' is invalid")
|
77
|
-
return 1
|
78
|
-
end
|
79
|
-
table_name = table_path_pair.pop
|
80
|
-
schema_name = table_path_pair.pop || "public"
|
81
|
-
full_table_paths[table_path] = "#{schema_name}.#{table_name}"
|
82
|
-
end
|
83
|
-
|
84
|
-
if params[:stats_flag]
|
85
|
-
count_sql = <<-EOF
|
86
|
-
select nspname || '.' || relname as full_table_path, reltuples, relpages
|
32
|
+
return full_table_paths
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.count_table_sizes(full_table_paths, params)
|
36
|
+
ActiveRecord::Base.establish_connection(params)
|
37
|
+
model_class = ActiveRecord::Base
|
38
|
+
if false && params[:stats_flag]
|
39
|
+
count_sql = <<-EOF
|
40
|
+
select nspname || '.' || relname as full_table_path, reltuples as record_size, relpages * 8 as byte_size
|
87
41
|
from pg_class
|
88
42
|
inner join pg_namespace
|
89
43
|
on pg_class.relnamespace = pg_namespace.oid
|
90
44
|
where relkind='r'
|
91
45
|
and (
|
92
46
|
#{
|
93
|
-
|
94
|
-
"(nspname || '.' || relname) = #{
|
47
|
+
full_table_paths.map{|full_table_path|
|
48
|
+
"(nspname || '.' || relname) = #{model_class.sanitize(full_table_path)}"
|
95
49
|
}.join(" or ")
|
96
50
|
}
|
97
51
|
)
|
98
|
-
|
99
|
-
|
100
|
-
|
52
|
+
EOF
|
53
|
+
else
|
54
|
+
count_sql = <<-EOF
|
101
55
|
#{
|
102
|
-
|
103
|
-
"(select #{
|
56
|
+
full_table_paths.map{|full_table_path|
|
57
|
+
"(select #{model_class.sanitize(full_table_path)} as full_table_path, count(*) as record_size from #{full_table_path})"
|
104
58
|
}.join(" union ")
|
105
59
|
}
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
results = ActiveRecord::Base.connection.execute count_sql
|
111
|
-
table_sizes = {}
|
112
|
-
results.each do |record|
|
113
|
-
table_path = record["full_table_path"]
|
114
|
-
if bytes_flag
|
115
|
-
table_sizes[table_path] = record["relpages"].to_i * 8
|
116
|
-
else
|
117
|
-
table_sizes[table_path] = record["reltuples"].to_i
|
118
|
-
end
|
119
|
-
end
|
120
|
-
table_paths.each do |table_path|
|
121
|
-
label = table_path.gsub(/[^a-zA-Z0-9]/, "_").downcase
|
122
|
-
table_size = table_sizes[full_table_paths[table_path]]
|
123
|
-
output_stream.puts "#{label}.value #{table_size}"
|
124
|
-
end
|
60
|
+
EOF
|
125
61
|
end
|
126
|
-
|
127
|
-
return
|
62
|
+
results = ActiveRecord::Base.connection.execute count_sql
|
63
|
+
return results
|
128
64
|
end
|
129
|
-
|
130
65
|
end
|
131
66
|
end
|
132
67
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "bin/cawcaw mysql table" do
|
4
|
+
before :all do
|
5
|
+
CawcawName.establish_connection({
|
6
|
+
:adapter=>"mysql2",
|
7
|
+
:host=>"localhost",
|
8
|
+
:port=>3306,
|
9
|
+
:username=>"mysql",
|
10
|
+
:password=>"mysql",
|
11
|
+
:database=>"cawcaw",
|
12
|
+
:encoding=>"utf8"
|
13
|
+
})
|
14
|
+
CawcawName.connection.create_table(:cawcaw_names) do |t|
|
15
|
+
t.column :name, :string
|
16
|
+
end
|
17
|
+
CawcawName.create(:name=>"foo")
|
18
|
+
CawcawName.create(:name=>"bar")
|
19
|
+
CawcawName.create(:name=>"baz")
|
20
|
+
end
|
21
|
+
|
22
|
+
after :all do
|
23
|
+
CawcawName.connection.drop_table(:cawcaw_names)
|
24
|
+
end
|
25
|
+
context "when table path is \"cawcaw_names\"" do
|
26
|
+
context "when munin param is not set" do
|
27
|
+
it "should output record size" do
|
28
|
+
result = `ruby -I lib ./bin/cawcaw mysql table --username mysql --password mysql --database cawcaw cawcaw_names`
|
29
|
+
record = result.chomp.split(/ /, 2)
|
30
|
+
record.should == ["cawcaw_names.value", "3"]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context "when munin param is config" do
|
34
|
+
it "should output munin config" do
|
35
|
+
result = `ruby -I lib ./bin/cawcaw mysql table --username mysql --password mysql --database cawcaw cawcaw_names config`
|
36
|
+
result = result.split(/\r?\n/).map{|l|l.split(/ /, 2)}
|
37
|
+
# result.each do |record| STDERR.puts record.inspect end
|
38
|
+
result.shift.should == ["graph_title", "mysql records"]
|
39
|
+
result.shift.should == ["graph_args", "--base 1000"]
|
40
|
+
result.shift.should == ["graph_vlabel", "records"]
|
41
|
+
result.shift.should == ["graph_category", "mysql"]
|
42
|
+
result.shift.should == ["graph_info", "mysql record size"]
|
43
|
+
result.shift.should == ["cawcaw_names.label", "cawcaw_names"]
|
44
|
+
result.shift.should == ["cawcaw_names.info", "cawcaw_names size"]
|
45
|
+
result.shift.should == ["cawcaw_names.draw", "AREA"]
|
46
|
+
result.shift.should == ["cawcaw_names.warning", "50000000"]
|
47
|
+
result.shift.should == ["cawcaw_names.critical", "100000000"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -20,11 +20,28 @@ describe "bin/cawcaw postgresql table" do
|
|
20
20
|
after :all do
|
21
21
|
CawcawName.connection.drop_table(:cawcaw_names)
|
22
22
|
end
|
23
|
-
context "when table path is
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
context "when table path is \"cawcaw_names\"" do
|
24
|
+
context "when munin param is not set" do
|
25
|
+
it "should output record size" do
|
26
|
+
result = `ruby -I lib ./bin/cawcaw postgresql table --username postgres --database cawcaw cawcaw_names`
|
27
|
+
record = result.chomp.split(/ /, 2)
|
28
|
+
record.should == ["cawcaw_names.value", "3"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context "when munin param is config" do
|
32
|
+
it "should output munin config" do
|
33
|
+
result = `ruby -I lib ./bin/cawcaw postgresql table --username postgres --database cawcaw cawcaw_names config`
|
34
|
+
result = result.split(/\r?\n/).map{|l|l.split(/ /, 2)}
|
35
|
+
# result.each do |record| STDERR.puts record.inspect end
|
36
|
+
result.shift.should == ["graph_title", "postgresql records"]
|
37
|
+
result.shift.should == ["graph_args", "--base 1000"]
|
38
|
+
result.shift.should == ["graph_vlabel", "records"]
|
39
|
+
result.shift.should == ["graph_category", "postgresql"]
|
40
|
+
result.shift.should == ["graph_info", "postgresql record size"]
|
41
|
+
result.shift.should == ["cawcaw_names.label", "cawcaw_names"]
|
42
|
+
result.shift.should == ["cawcaw_names.info", "cawcaw_names size"]
|
43
|
+
result.shift.should == ["cawcaw_names.draw", "AREA"]
|
44
|
+
end
|
28
45
|
end
|
29
46
|
end
|
30
47
|
end
|
metadata
CHANGED
@@ -1,233 +1,239 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cawcaw
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Kenji Hara
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
|
18
|
+
date: 2013-01-21 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
23
|
none: false
|
18
|
-
requirements:
|
24
|
+
requirements:
|
19
25
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 25
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 2
|
31
|
+
- 11
|
21
32
|
version: 3.2.11
|
22
33
|
type: :runtime
|
34
|
+
name: activerecord
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
23
37
|
prerelease: false
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 3.2.11
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: activerecord-postgresql-adapter
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
33
39
|
none: false
|
34
|
-
requirements:
|
40
|
+
requirements:
|
35
41
|
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 5
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 3
|
47
|
+
- 11
|
48
|
+
version: 0.3.11
|
38
49
|
type: :runtime
|
50
|
+
name: mysql2
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
39
53
|
prerelease: false
|
40
|
-
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
55
|
none: false
|
42
|
-
requirements:
|
56
|
+
requirements:
|
43
57
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 29
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
- 1
|
45
64
|
version: 0.0.1
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: bunnish
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.1.2
|
54
65
|
type: :runtime
|
66
|
+
name: activerecord-postgresql-adapter
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
55
69
|
prerelease: false
|
56
|
-
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
57
71
|
none: false
|
58
|
-
requirements:
|
72
|
+
requirements:
|
59
73
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 31
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
- 1
|
79
|
+
- 2
|
61
80
|
version: 0.1.2
|
62
|
-
|
63
|
-
name:
|
64
|
-
|
65
|
-
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 2.12.0
|
70
|
-
type: :development
|
81
|
+
type: :runtime
|
82
|
+
name: bunnish
|
83
|
+
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
71
85
|
prerelease: false
|
72
|
-
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
73
87
|
none: false
|
74
|
-
requirements:
|
88
|
+
requirements:
|
75
89
|
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 63
|
92
|
+
segments:
|
93
|
+
- 2
|
94
|
+
- 12
|
95
|
+
- 0
|
77
96
|
version: 2.12.0
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: yard
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ~>
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 0.8.3
|
86
97
|
type: :development
|
98
|
+
name: rspec
|
99
|
+
version_requirements: *id005
|
100
|
+
- !ruby/object:Gem::Dependency
|
87
101
|
prerelease: false
|
88
|
-
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
89
103
|
none: false
|
90
|
-
requirements:
|
104
|
+
requirements:
|
91
105
|
- - ~>
|
92
|
-
- !ruby/object:Gem::Version
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 57
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
- 8
|
111
|
+
- 3
|
93
112
|
version: 0.8.3
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: redcarpet
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 2.2.2
|
102
113
|
type: :development
|
114
|
+
name: yard
|
115
|
+
version_requirements: *id006
|
116
|
+
- !ruby/object:Gem::Dependency
|
103
117
|
prerelease: false
|
104
|
-
|
118
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
105
119
|
none: false
|
106
|
-
requirements:
|
120
|
+
requirements:
|
107
121
|
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 2
|
126
|
+
- 2
|
127
|
+
- 2
|
109
128
|
version: 2.2.2
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: rdoc
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ~>
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '3.12'
|
118
129
|
type: :development
|
130
|
+
name: redcarpet
|
131
|
+
version_requirements: *id007
|
132
|
+
- !ruby/object:Gem::Dependency
|
119
133
|
prerelease: false
|
120
|
-
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ~>
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '3.12'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: bundler
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
129
135
|
none: false
|
130
|
-
requirements:
|
136
|
+
requirements:
|
131
137
|
- - ~>
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 31
|
140
|
+
segments:
|
141
|
+
- 3
|
142
|
+
- 12
|
143
|
+
version: "3.12"
|
134
144
|
type: :development
|
145
|
+
name: rdoc
|
146
|
+
version_requirements: *id008
|
147
|
+
- !ruby/object:Gem::Dependency
|
135
148
|
prerelease: false
|
136
|
-
|
149
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
137
150
|
none: false
|
138
|
-
requirements:
|
151
|
+
requirements:
|
139
152
|
- - ~>
|
140
|
-
- !ruby/object:Gem::Version
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 25
|
155
|
+
segments:
|
156
|
+
- 1
|
157
|
+
- 2
|
158
|
+
- 3
|
141
159
|
version: 1.2.3
|
142
|
-
- !ruby/object:Gem::Dependency
|
143
|
-
name: jeweler
|
144
|
-
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
|
-
requirements:
|
147
|
-
- - ~>
|
148
|
-
- !ruby/object:Gem::Version
|
149
|
-
version: 1.8.4
|
150
160
|
type: :development
|
161
|
+
name: bundler
|
162
|
+
version_requirements: *id009
|
163
|
+
- !ruby/object:Gem::Dependency
|
151
164
|
prerelease: false
|
152
|
-
|
165
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
153
166
|
none: false
|
154
|
-
requirements:
|
167
|
+
requirements:
|
155
168
|
- - ~>
|
156
|
-
- !ruby/object:Gem::Version
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
hash: 63
|
171
|
+
segments:
|
172
|
+
- 1
|
173
|
+
- 8
|
174
|
+
- 4
|
157
175
|
version: 1.8.4
|
158
|
-
- !ruby/object:Gem::Dependency
|
159
|
-
name: simplecov
|
160
|
-
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
|
-
requirements:
|
163
|
-
- - ~>
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: 0.7.1
|
166
176
|
type: :development
|
177
|
+
name: jeweler
|
178
|
+
version_requirements: *id010
|
179
|
+
- !ruby/object:Gem::Dependency
|
167
180
|
prerelease: false
|
168
|
-
|
181
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
169
182
|
none: false
|
170
|
-
requirements:
|
183
|
+
requirements:
|
171
184
|
- - ~>
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
- - ~>
|
180
|
-
- !ruby/object:Gem::Version
|
181
|
-
version: 0.2.3
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
hash: 23
|
187
|
+
segments:
|
188
|
+
- 1
|
189
|
+
- 0
|
190
|
+
- 0
|
191
|
+
version: 1.0.0
|
182
192
|
type: :development
|
193
|
+
name: rcov
|
194
|
+
version_requirements: *id011
|
195
|
+
- !ruby/object:Gem::Dependency
|
183
196
|
prerelease: false
|
184
|
-
|
185
|
-
none: false
|
186
|
-
requirements:
|
187
|
-
- - ~>
|
188
|
-
- !ruby/object:Gem::Version
|
189
|
-
version: 0.2.3
|
190
|
-
- !ruby/object:Gem::Dependency
|
191
|
-
name: ci_reporter
|
192
|
-
requirement: !ruby/object:Gem::Requirement
|
197
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
193
198
|
none: false
|
194
|
-
requirements:
|
199
|
+
requirements:
|
195
200
|
- - ~>
|
196
|
-
- !ruby/object:Gem::Version
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
hash: 49
|
203
|
+
segments:
|
204
|
+
- 1
|
205
|
+
- 8
|
206
|
+
- 3
|
197
207
|
version: 1.8.3
|
198
208
|
type: :development
|
209
|
+
name: ci_reporter
|
210
|
+
version_requirements: *id012
|
211
|
+
- !ruby/object:Gem::Dependency
|
199
212
|
prerelease: false
|
200
|
-
|
213
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
201
214
|
none: false
|
202
|
-
requirements:
|
203
|
-
- -
|
204
|
-
- !ruby/object:Gem::Version
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
requirements:
|
211
|
-
- - ! '>='
|
212
|
-
- !ruby/object:Gem::Version
|
215
|
+
requirements:
|
216
|
+
- - ">="
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
hash: 15
|
219
|
+
segments:
|
220
|
+
- 3
|
221
|
+
- 2
|
222
|
+
- 0
|
213
223
|
version: 3.2.0
|
214
224
|
type: :development
|
215
|
-
|
216
|
-
version_requirements:
|
217
|
-
none: false
|
218
|
-
requirements:
|
219
|
-
- - ! '>='
|
220
|
-
- !ruby/object:Gem::Version
|
221
|
-
version: 3.2.0
|
225
|
+
name: flog
|
226
|
+
version_requirements: *id013
|
222
227
|
description: cawcaw RubyGem
|
223
228
|
email: haracane@gmail.com
|
224
|
-
executables:
|
229
|
+
executables:
|
225
230
|
- cawcaw
|
226
231
|
extensions: []
|
227
|
-
|
232
|
+
|
233
|
+
extra_rdoc_files:
|
228
234
|
- LICENSE.txt
|
229
235
|
- README.md
|
230
|
-
files:
|
236
|
+
files:
|
231
237
|
- .document
|
232
238
|
- .rspec
|
233
239
|
- Gemfile
|
@@ -238,44 +244,55 @@ files:
|
|
238
244
|
- bin/cawcaw
|
239
245
|
- cawcaw.gemspec
|
240
246
|
- lib/cawcaw.rb
|
247
|
+
- lib/cawcaw/command/database.rb
|
248
|
+
- lib/cawcaw/command/database/table.rb
|
241
249
|
- lib/cawcaw/command/hadoop.rb
|
242
250
|
- lib/cawcaw/command/hadoop/dfs.rb
|
251
|
+
- lib/cawcaw/command/mysql.rb
|
252
|
+
- lib/cawcaw/command/mysql/table.rb
|
243
253
|
- lib/cawcaw/command/postgresql.rb
|
244
254
|
- lib/cawcaw/command/postgresql/table.rb
|
245
255
|
- lib/cawcaw/command/rabbitmq.rb
|
246
256
|
- lib/cawcaw/command/rabbitmq/queue_count.rb
|
247
257
|
- lib/cawcaw/core/common.rb
|
248
258
|
- spec/bin/cawcaw/hadoop/dfs_spec.rb
|
259
|
+
- spec/bin/cawcaw/mysql/table_spec.rb
|
249
260
|
- spec/bin/cawcaw/postgresql/table_spec.rb
|
250
261
|
- spec/bin/cawcaw/rabbitmq/queue_count_spec.rb
|
251
262
|
- spec/lib/cawcaw_spec.rb
|
252
263
|
- spec/spec_helper.rb
|
253
264
|
homepage: http://github.com/haracane/cawcaw
|
254
|
-
licenses:
|
265
|
+
licenses:
|
255
266
|
- MIT
|
256
267
|
post_install_message:
|
257
268
|
rdoc_options: []
|
258
|
-
|
269
|
+
|
270
|
+
require_paths:
|
259
271
|
- lib
|
260
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
272
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
261
273
|
none: false
|
262
|
-
requirements:
|
263
|
-
- -
|
264
|
-
- !ruby/object:Gem::Version
|
265
|
-
|
266
|
-
segments:
|
274
|
+
requirements:
|
275
|
+
- - ">="
|
276
|
+
- !ruby/object:Gem::Version
|
277
|
+
hash: 3
|
278
|
+
segments:
|
267
279
|
- 0
|
268
|
-
|
269
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
|
+
version: "0"
|
281
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
270
282
|
none: false
|
271
|
-
requirements:
|
272
|
-
- -
|
273
|
-
- !ruby/object:Gem::Version
|
274
|
-
|
283
|
+
requirements:
|
284
|
+
- - ">="
|
285
|
+
- !ruby/object:Gem::Version
|
286
|
+
hash: 3
|
287
|
+
segments:
|
288
|
+
- 0
|
289
|
+
version: "0"
|
275
290
|
requirements: []
|
291
|
+
|
276
292
|
rubyforge_project:
|
277
293
|
rubygems_version: 1.8.24
|
278
294
|
signing_key:
|
279
295
|
specification_version: 3
|
280
296
|
summary: cawcaw RubyGem
|
281
297
|
test_files: []
|
298
|
+
|