cawcaw 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/cawcaw.gemspec +83 -0
- data/lib/cawcaw/command/hadoop/dfs.rb +21 -8
- data/lib/cawcaw/core/common.rb +8 -0
- data/spec/bin/cawcaw/hadoop/dfs_spec.rb +116 -0
- data/spec/bin/cawcaw/rabbitmq/queue_count_spec.rb +40 -0
- metadata +7 -4
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/cawcaw.gemspec
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "cawcaw"
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kenji Hara"]
|
12
|
+
s.date = "2013-01-02"
|
13
|
+
s.description = "cawcaw RubyGem"
|
14
|
+
s.email = "haracane@gmail.com"
|
15
|
+
s.executables = ["cawcaw"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/cawcaw",
|
29
|
+
"cawcaw.gemspec",
|
30
|
+
"lib/cawcaw.rb",
|
31
|
+
"lib/cawcaw/command/hadoop.rb",
|
32
|
+
"lib/cawcaw/command/hadoop/dfs.rb",
|
33
|
+
"lib/cawcaw/command/rabbitmq.rb",
|
34
|
+
"lib/cawcaw/command/rabbitmq/queue_count.rb",
|
35
|
+
"lib/cawcaw/core/common.rb",
|
36
|
+
"spec/bin/cawcaw/hadoop/dfs_spec.rb",
|
37
|
+
"spec/bin/cawcaw/rabbitmq/queue_count_spec.rb",
|
38
|
+
"spec/lib/cawcaw_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
s.homepage = "http://github.com/haracane/cawcaw"
|
42
|
+
s.licenses = ["MIT"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = "1.8.24"
|
45
|
+
s.summary = "cawcaw RubyGem"
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<bunnish>, [">= 0.1.2"])
|
52
|
+
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
53
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<simplecov-rcov>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<ci_reporter>, [">= 1.7.0"])
|
59
|
+
s.add_development_dependency(%q<flog>, [">= 3.2.0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<bunnish>, [">= 0.1.2"])
|
62
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
63
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
66
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<simplecov-rcov>, [">= 0"])
|
68
|
+
s.add_dependency(%q<ci_reporter>, [">= 1.7.0"])
|
69
|
+
s.add_dependency(%q<flog>, [">= 3.2.0"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<bunnish>, [">= 0.1.2"])
|
73
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
74
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
75
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
77
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
78
|
+
s.add_dependency(%q<simplecov-rcov>, [">= 0"])
|
79
|
+
s.add_dependency(%q<ci_reporter>, [">= 1.7.0"])
|
80
|
+
s.add_dependency(%q<flog>, [">= 3.2.0"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -14,8 +14,6 @@ module Cawcaw
|
|
14
14
|
params[:label_warning] ||= 5000000
|
15
15
|
params[:label_critical] ||= 5000000
|
16
16
|
|
17
|
-
params[:hadoop_command] ||= "hadoop"
|
18
|
-
|
19
17
|
if params[:stdin_flag]
|
20
18
|
hdfs_paths = []
|
21
19
|
while line = input_stream.gets
|
@@ -35,6 +33,15 @@ module Cawcaw
|
|
35
33
|
return 1
|
36
34
|
end
|
37
35
|
|
36
|
+
absolute_hdfs_paths = {}
|
37
|
+
hdfs_paths.each do |hdfs_path|
|
38
|
+
if /^\// =~ hdfs_path
|
39
|
+
absolute_hdfs_paths[hdfs_path] = hdfs_path
|
40
|
+
else
|
41
|
+
absolute_hdfs_paths[hdfs_path] = "#{params[:hadoop_working_directory]}/#{hdfs_path}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
38
45
|
case command
|
39
46
|
when "autoconf"
|
40
47
|
output_stream.puts "yes"
|
@@ -61,14 +68,20 @@ graph_info #{params[:graph_info]}
|
|
61
68
|
label_draw = "STACK"
|
62
69
|
end
|
63
70
|
else
|
64
|
-
result = `#{params[:hadoop_command]} dfs -dus #{hdfs_paths.join(" ")}`
|
65
|
-
|
66
|
-
|
67
|
-
result.each do |
|
71
|
+
result = `#{params[:hadoop_command]} dfs -dus #{hdfs_paths.map{|hdfs_path|absolute_hdfs_paths[hdfs_path]}.join(" ")}`
|
72
|
+
# STDERR.puts result
|
73
|
+
hdfs_sizes = {}
|
74
|
+
result.split(/\r?\n/).each do |line|
|
75
|
+
record = line.split(/\s+/)
|
68
76
|
hdfs_uri = record[0]
|
69
|
-
hdfs_size = record[1]
|
70
77
|
hdfs_uri = URI.parse(hdfs_uri)
|
71
|
-
|
78
|
+
hdfs_sizes[hdfs_uri.path] = record[1]
|
79
|
+
end
|
80
|
+
# STDERR.puts hdfs_sizes.inspect
|
81
|
+
|
82
|
+
hdfs_paths.each do |hdfs_path|
|
83
|
+
hdfs_size = hdfs_sizes[absolute_hdfs_paths[hdfs_path]]
|
84
|
+
label = hdfs_path.gsub(/[^a-zA-Z0-9]/, "_").downcase
|
72
85
|
output_stream.puts "#{label}.value #{hdfs_size}"
|
73
86
|
end
|
74
87
|
end
|
data/lib/cawcaw/core/common.rb
CHANGED
@@ -7,6 +7,10 @@ module Cawcaw
|
|
7
7
|
graph_vlabel = nil
|
8
8
|
graph_category = nil
|
9
9
|
graph_info = nil
|
10
|
+
|
11
|
+
hadoop_working_directory = "/user/#{ENV["USER"]}"
|
12
|
+
hadoop_command = "hadoop"
|
13
|
+
|
10
14
|
stdin_flag = false
|
11
15
|
verbose_flag = false
|
12
16
|
|
@@ -31,6 +35,9 @@ module Cawcaw
|
|
31
35
|
label_critical = argv.shift.to_i
|
32
36
|
when "--hadoop-command"
|
33
37
|
hadoop_command = argv.shift
|
38
|
+
when "--hadoop-wdir"
|
39
|
+
hadoop_working_directory = argv.shift
|
40
|
+
hadoop_working_directory = hadoop_working_directory.gsub(/\/$/, "")
|
34
41
|
when "--stdin"
|
35
42
|
stdin_flag = true
|
36
43
|
when "--verbose"
|
@@ -56,6 +63,7 @@ module Cawcaw
|
|
56
63
|
:label_warning=>label_warning,
|
57
64
|
:label_critical=>label_critical,
|
58
65
|
:hadoop_command=>hadoop_command,
|
66
|
+
:hadoop_working_directory=>hadoop_working_directory,
|
59
67
|
:stdin_flag=>stdin_flag,
|
60
68
|
:verbose_flag=>verbose_flag
|
61
69
|
}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "bin/cawcaw hadoop dfs" do
|
4
|
+
before :all do
|
5
|
+
tmpfile = Tempfile.new("cawcaw_spec.rb")
|
6
|
+
tmpfile.puts "foo bar baz"
|
7
|
+
tmpfile.close
|
8
|
+
system("hadoop dfs -rmr cawcaw-test >/dev/null 2>/dev/null")
|
9
|
+
system("hadoop dfs -put #{tmpfile.path} cawcaw-test/")
|
10
|
+
end
|
11
|
+
context "when hdfs path is absolute" do
|
12
|
+
it "should output hadoop dfs config" do
|
13
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw hadoop dfs /user/#{ENV["USER"]}/cawcaw-test config`
|
14
|
+
hash = {}
|
15
|
+
result.split(/\r?\n/).each do |line|
|
16
|
+
record = line.split(/ /, 2)
|
17
|
+
hash[record[0]] = record[1]
|
18
|
+
end
|
19
|
+
result = hash
|
20
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
21
|
+
result["graph_title"].should == "HDFS size"
|
22
|
+
result["graph_args"].should == "--base 1000"
|
23
|
+
result["graph_vlabel"].should == "bytes"
|
24
|
+
result["graph_category"].should == "hadoop"
|
25
|
+
result["graph_info"].should == "HDFS size"
|
26
|
+
result["_user_#{ENV["USER"]}_cawcaw_test.label"].should == "/user/#{ENV["USER"]}/cawcaw-test"
|
27
|
+
result["_user_#{ENV["USER"]}_cawcaw_test.info"].should == "/user/#{ENV["USER"]}/cawcaw-test size"
|
28
|
+
result["_user_#{ENV["USER"]}_cawcaw_test.draw"].should == "AREA"
|
29
|
+
result["_user_#{ENV["USER"]}_cawcaw_test.warning"].should == "5000000"
|
30
|
+
result["_user_#{ENV["USER"]}_cawcaw_test.critical"].should == "5000000"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should output hadoop dfs value" do
|
34
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw hadoop dfs /user/#{ENV["USER"]}/cawcaw-test`
|
35
|
+
hash = {}
|
36
|
+
result.split(/\r?\n/).each do |line|
|
37
|
+
record = line.split(/ /, 2)
|
38
|
+
hash[record[0]] = record[1]
|
39
|
+
end
|
40
|
+
result = hash
|
41
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
42
|
+
result["_user_#{ENV["USER"]}_cawcaw_test.value"].should == "12"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
context "when hdfs path is relative" do
|
46
|
+
context "with hadoop-wdir option" do
|
47
|
+
it "should output hadoop dfs config" do
|
48
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw hadoop dfs --hadoop-wdir /user #{ENV["USER"]}/cawcaw-test config`
|
49
|
+
hash = {}
|
50
|
+
result.split(/\r?\n/).each do |line|
|
51
|
+
record = line.split(/ /, 2)
|
52
|
+
hash[record[0]] = record[1]
|
53
|
+
end
|
54
|
+
result = hash
|
55
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
56
|
+
result["graph_title"].should == "HDFS size"
|
57
|
+
result["graph_args"].should == "--base 1000"
|
58
|
+
result["graph_vlabel"].should == "bytes"
|
59
|
+
result["graph_category"].should == "hadoop"
|
60
|
+
result["graph_info"].should == "HDFS size"
|
61
|
+
result["#{ENV["USER"]}_cawcaw_test.label"].should == "#{ENV["USER"]}/cawcaw-test"
|
62
|
+
result["#{ENV["USER"]}_cawcaw_test.info"].should == "#{ENV["USER"]}/cawcaw-test size"
|
63
|
+
result["#{ENV["USER"]}_cawcaw_test.draw"].should == "AREA"
|
64
|
+
result["#{ENV["USER"]}_cawcaw_test.warning"].should == "5000000"
|
65
|
+
result["#{ENV["USER"]}_cawcaw_test.critical"].should == "5000000"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should output hadoop dfs value" do
|
69
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw hadoop dfs --hadoop-wdir /user #{ENV["USER"]}/cawcaw-test`
|
70
|
+
hash = {}
|
71
|
+
result.split(/\r?\n/).each do |line|
|
72
|
+
record = line.split(/ /, 2)
|
73
|
+
hash[record[0]] = record[1]
|
74
|
+
end
|
75
|
+
result = hash
|
76
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
77
|
+
result["#{ENV["USER"]}_cawcaw_test.value"].should == "12"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "without hadoop-wdir option" do
|
82
|
+
it "should output hadoop dfs config" do
|
83
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw hadoop dfs cawcaw-test config`
|
84
|
+
hash = {}
|
85
|
+
result.split(/\r?\n/).each do |line|
|
86
|
+
record = line.split(/ /, 2)
|
87
|
+
hash[record[0]] = record[1]
|
88
|
+
end
|
89
|
+
result = hash
|
90
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
91
|
+
result["graph_title"].should == "HDFS size"
|
92
|
+
result["graph_args"].should == "--base 1000"
|
93
|
+
result["graph_vlabel"].should == "bytes"
|
94
|
+
result["graph_category"].should == "hadoop"
|
95
|
+
result["graph_info"].should == "HDFS size"
|
96
|
+
result["cawcaw_test.label"].should == "cawcaw-test"
|
97
|
+
result["cawcaw_test.info"].should == "cawcaw-test size"
|
98
|
+
result["cawcaw_test.draw"].should == "AREA"
|
99
|
+
result["cawcaw_test.warning"].should == "5000000"
|
100
|
+
result["cawcaw_test.critical"].should == "5000000"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should output hadoop dfs value" do
|
104
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw hadoop dfs cawcaw-test`
|
105
|
+
hash = {}
|
106
|
+
result.split(/\r?\n/).each do |line|
|
107
|
+
record = line.split(/ /, 2)
|
108
|
+
hash[record[0]] = record[1]
|
109
|
+
end
|
110
|
+
result = hash
|
111
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
112
|
+
result["cawcaw_test.value"].should == "12"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "bin/cawcaw rabbitmq queue-count" do
|
4
|
+
before :all do
|
5
|
+
system("bunnish delete cawcaw-test-queue")
|
6
|
+
system("echo \"foo\nbar\nbaz\" | bunnish publish cawcaw-test-queue")
|
7
|
+
end
|
8
|
+
it "should output rabbitmq queue-count config" do
|
9
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw rabbitmq queue-count cawcaw-test-queue config`
|
10
|
+
hash = {}
|
11
|
+
result.split(/\r?\n/).each do |line|
|
12
|
+
record = line.split(/ /, 2)
|
13
|
+
hash[record[0]] = record[1]
|
14
|
+
end
|
15
|
+
result = hash
|
16
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
17
|
+
result["graph_title"].should == "Queue count"
|
18
|
+
result["graph_args"].should == "--base 1000"
|
19
|
+
result["graph_vlabel"].should == "messages"
|
20
|
+
result["graph_category"].should == "rabbitmq"
|
21
|
+
result["graph_info"].should == "Queue count"
|
22
|
+
result["cawcaw_test_queue.label"].should == "cawcaw-test-queue"
|
23
|
+
result["cawcaw_test_queue.info"].should == "cawcaw-test-queue queue count"
|
24
|
+
result["cawcaw_test_queue.draw"].should == "AREA"
|
25
|
+
result["cawcaw_test_queue.warning"].should == "5000000"
|
26
|
+
result["cawcaw_test_queue.critical"].should == "5000000"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should output rabbitmq queue-count value" do
|
30
|
+
result = `#{Cawcaw::RUBY_CMD} #{Cawcaw::BIN_DIR}/cawcaw rabbitmq queue-count cawcaw-test-queue`
|
31
|
+
hash = {}
|
32
|
+
result.split(/\r?\n/).each do |line|
|
33
|
+
record = line.split(/ /, 2)
|
34
|
+
hash[record[0]] = record[1]
|
35
|
+
end
|
36
|
+
result = hash
|
37
|
+
# result.each_pair do |key, val| STDERR.puts "result[#{key.inspect}].should == #{val.inspect}" end
|
38
|
+
result["cawcaw_test_queue.value"].should == "3"
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cawcaw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.1.
|
21
|
+
version: 0.1.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.1.
|
29
|
+
version: 0.1.2
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,12 +172,15 @@ files:
|
|
172
172
|
- Rakefile
|
173
173
|
- VERSION
|
174
174
|
- bin/cawcaw
|
175
|
+
- cawcaw.gemspec
|
175
176
|
- lib/cawcaw.rb
|
176
177
|
- lib/cawcaw/command/hadoop.rb
|
177
178
|
- lib/cawcaw/command/hadoop/dfs.rb
|
178
179
|
- lib/cawcaw/command/rabbitmq.rb
|
179
180
|
- lib/cawcaw/command/rabbitmq/queue_count.rb
|
180
181
|
- lib/cawcaw/core/common.rb
|
182
|
+
- spec/bin/cawcaw/hadoop/dfs_spec.rb
|
183
|
+
- spec/bin/cawcaw/rabbitmq/queue_count_spec.rb
|
181
184
|
- spec/lib/cawcaw_spec.rb
|
182
185
|
- spec/spec_helper.rb
|
183
186
|
homepage: http://github.com/haracane/cawcaw
|
@@ -195,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
198
|
version: '0'
|
196
199
|
segments:
|
197
200
|
- 0
|
198
|
-
hash:
|
201
|
+
hash: -260789276697941311
|
199
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
203
|
none: false
|
201
204
|
requirements:
|