nginx_utils 0.0.7 → 0.0.8
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/.coveralls.yml +1 -0
- data/Gemfile +4 -0
- data/README.md +4 -0
- data/lib/nginx_utils/status.rb +23 -17
- data/lib/nginx_utils/version.rb +1 -1
- data/spec/nginx_utils/status_spec.rb +22 -6
- data/spec/spec_helper.rb +3 -0
- metadata +5 -4
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: j5c7RRcpsMCwX1qif9oQyvF6qOfqKv0CV
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# NginxUtils
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/nginx_utils)
|
3
4
|
[](https://travis-ci.org/i2bskn/nginx_utils)
|
5
|
+
[](https://coveralls.io/r/i2bskn/nginx_utils?branch=master)
|
6
|
+
[](https://codeclimate.com/github/i2bskn/nginx_utils)
|
7
|
+
|
4
8
|
|
5
9
|
Nginx utilities.
|
6
10
|
|
data/lib/nginx_utils/status.rb
CHANGED
@@ -7,24 +7,30 @@ module NginxUtils
|
|
7
7
|
host = options[:host] || "localhost"
|
8
8
|
port = options[:port] || 80
|
9
9
|
path = options[:path] || "/nginx_status"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
requests: server[2],
|
21
|
-
reading: rww[0],
|
22
|
-
writing: rww[1],
|
23
|
-
waiting: rww[2]
|
24
|
-
}
|
10
|
+
|
11
|
+
req = Net::HTTP::Get.new(path)
|
12
|
+
res = Net::HTTP.start(host, port){|http| http.request(req)}
|
13
|
+
parse res
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def parse(response)
|
18
|
+
status = response.body.split("\n")
|
19
|
+
formexp(status[0], status[2].split, status[3].split)
|
25
20
|
rescue
|
26
|
-
raise "
|
27
|
-
|
21
|
+
raise "Parse error"
|
22
|
+
end
|
23
|
+
|
24
|
+
def formexp(ac_line, server_line, rww_line)
|
25
|
+
{
|
26
|
+
active_connections: ac_line.split(":")[1].to_i,
|
27
|
+
accepts: server_line[0].to_i,
|
28
|
+
handled: server_line[1].to_i,
|
29
|
+
requests: server_line[2].to_i,
|
30
|
+
reading: rww_line[1].to_i,
|
31
|
+
writing: rww_line[3].to_i,
|
32
|
+
waiting: rww_line[5].to_i
|
33
|
+
}
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
data/lib/nginx_utils/version.rb
CHANGED
@@ -3,19 +3,35 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe "NginxUtils::Status" do
|
6
|
+
let(:body) {"Active connections: 1 \nserver accepts handled requests\n 4 5 51 \nReading: 1 Writing: 3 Waiting: 2 \n"}
|
7
|
+
let(:status) {{active_connections: 1, accepts: 4, handled: 5, requests: 51, reading: 1, writing: 3, waiting: 2}}
|
8
|
+
|
6
9
|
describe ".get" do
|
10
|
+
before {NginxUtils::Status.stub(:parse).and_return(nil)}
|
11
|
+
|
7
12
|
it "should get status" do
|
8
|
-
body = "Active connections: 1 \nserver accepts handled requests\n 4 5 51 \nReading: 1 Writing: 3 Waiting: 2 \n"
|
9
|
-
status = {active_connections: 1, accepts: 4, handled: 5, requests: 51, reading: 1, writing: 3, waiting: 2}
|
10
13
|
response = double("http response mock", body: body)
|
11
14
|
Net::HTTP.should_receive(:start).and_return(response)
|
12
|
-
expect(NginxUtils::Status.get).
|
15
|
+
expect(proc{NginxUtils::Status.get}).not_to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".parse" do
|
20
|
+
it "should return status hash" do
|
21
|
+
response = double("http response mock", body: body)
|
22
|
+
expect(NginxUtils::Status.send(:parse, response)).to eq(status)
|
13
23
|
end
|
14
24
|
|
15
|
-
it "should generate an exception if
|
25
|
+
it "should generate an exception if parse failed" do
|
16
26
|
response = double("http response mock", body: "invalid content")
|
17
|
-
|
18
|
-
|
27
|
+
expect(proc{NginxUtils::Status.send(:parse, response)}).to raise_error(RuntimeError, "Parse error")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".formexp" do
|
32
|
+
it "should return status hash with format" do
|
33
|
+
args = body.split("\n")
|
34
|
+
expect(NginxUtils::Status.send(:formexp, args[0], args[2].split, args[3].split)).to eq(status)
|
19
35
|
end
|
20
36
|
end
|
21
37
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nginx_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -83,6 +83,7 @@ executables:
|
|
83
83
|
extensions: []
|
84
84
|
extra_rdoc_files: []
|
85
85
|
files:
|
86
|
+
- .coveralls.yml
|
86
87
|
- .gitignore
|
87
88
|
- .travis.yml
|
88
89
|
- Gemfile
|
@@ -117,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
118
|
version: '0'
|
118
119
|
segments:
|
119
120
|
- 0
|
120
|
-
hash: -
|
121
|
+
hash: -1389210587237094459
|
121
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
123
|
none: false
|
123
124
|
requirements:
|
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
127
|
version: '0'
|
127
128
|
segments:
|
128
129
|
- 0
|
129
|
-
hash: -
|
130
|
+
hash: -1389210587237094459
|
130
131
|
requirements: []
|
131
132
|
rubyforge_project:
|
132
133
|
rubygems_version: 1.8.25
|