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 ADDED
@@ -0,0 +1 @@
1
+ repo_token: j5c7RRcpsMCwX1qif9oQyvF6qOfqKv0CV
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in nginx_utils.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'coveralls', require: false
8
+ end
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # NginxUtils
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/nginx_utils.png)](http://badge.fury.io/rb/nginx_utils)
3
4
  [![Build Status](https://travis-ci.org/i2bskn/nginx_utils.png?branch=master)](https://travis-ci.org/i2bskn/nginx_utils)
5
+ [![Coverage Status](https://coveralls.io/repos/i2bskn/nginx_utils/badge.png?branch=master)](https://coveralls.io/r/i2bskn/nginx_utils?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/i2bskn/nginx_utils.png)](https://codeclimate.com/github/i2bskn/nginx_utils)
7
+
4
8
 
5
9
  Nginx utilities.
6
10
 
@@ -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
- begin
11
- req = Net::HTTP::Get.new(path)
12
- res = Net::HTTP.start(host, port){|http| http.request(req)}
13
- status = res.body.split("\n")
14
- server = status[2].split.map{|i| i.to_i}
15
- rww = status[3].split.select{|i| /^[0-9]+$/ =~ i}.map{|i| i.to_i}
16
- {
17
- active_connections: status[0].split(":").last.gsub(/\s/, "").to_i,
18
- accepts: server[0],
19
- handled: server[1],
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 "Nginx status get failed"
27
- end
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
@@ -1,3 +1,3 @@
1
1
  module NginxUtils
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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).to eq(status)
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 status get fails" do
25
+ it "should generate an exception if parse failed" do
16
26
  response = double("http response mock", body: "invalid content")
17
- Net::HTTP.should_receive(:start).and_return(response)
18
- expect(proc{NginxUtils::Status.get}).to raise_error("Nginx status get failed")
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
@@ -1 +1,4 @@
1
1
  require "nginx_utils"
2
+
3
+ require "coveralls"
4
+ Coveralls.wear!
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.7
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-28 00:00:00.000000000 Z
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: -574939535063558817
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: -574939535063558817
130
+ hash: -1389210587237094459
130
131
  requirements: []
131
132
  rubyforge_project:
132
133
  rubygems_version: 1.8.25