rack-unix_domain_socket_status 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/lib/rack/unix_domain_socket_status.rb +52 -0
- data/rack-unix_domain_socket_status.gemspec +22 -0
- data/spec/rack-unix_domain_socket_status_spec.rb +44 -0
- data/spec/spec_helper.rb +14 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48e9c316275ff281bd9a9fe846e129bf1f4a0fa6
|
4
|
+
data.tar.gz: 7d3d49b04b3a87816421c50bbcc017820a96ead2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da8a8bb3170137de949a81d81312fc5c608d2ad85b32052380571c40094e57d5f410e0a3b1678e84d4fe1fda5df72fb573babefa90730e8ba8ea908852a41c86
|
7
|
+
data.tar.gz: b8142738ea553985b2ef21b3b1bff37b4c258a6171d8fcd28cc18535cb545fc6dd7a5f5ffb4189f922bcfa80100183cabb299c33fa7ba6da46cec6a26b7b9720
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in rack-unix_domain_socket_status.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'pry'
|
8
|
+
end
|
9
|
+
group :test do
|
10
|
+
gem 'rack'
|
11
|
+
#gem 'coveralls', require: false
|
12
|
+
gem 'rspec'
|
13
|
+
gem 'simplecov', require: false
|
14
|
+
gem 'simplecov-rcov', require: false
|
15
|
+
gem 'timecop'
|
16
|
+
end
|
17
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 SpringMT
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Rack::UnixDomainSocketStatus
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rack-unix_domain_socket_status'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rack-unix_domain_socket_status
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/rack-unix_domain_socket_status/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
task :test do
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
RSpec::Core::RakeTask.new(:test) do |spec|
|
10
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class UnixDomainSocketStatus
|
5
|
+
def initialize(app, options={})
|
6
|
+
@app = app
|
7
|
+
raw_unix_domain_socket_path = options.delete(:unix_domain_socket_path) || raise('unix_domain_socket_path is required')
|
8
|
+
@unix_domain_socket_path = Regexp.escape raw_unix_domain_socket_path.force_encoding(Encoding::BINARY)
|
9
|
+
@proc_net_unix_path = options.delete(:proc_net_unix_path) || '/proc/net/unix'
|
10
|
+
@options = {
|
11
|
+
path: '/unix_status',
|
12
|
+
status: 200,
|
13
|
+
headers: {'Content-Type' => 'application/json'},
|
14
|
+
}.merge(options)
|
15
|
+
@enable = ::File.exist? @proc_net_unix_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
if @enable && env['PATH_INFO'] == @options[:path]
|
20
|
+
status = @options[:status]
|
21
|
+
body = [calculate_unix_domain_socket_status]
|
22
|
+
headers = @options[:headers]
|
23
|
+
[status, headers, body]
|
24
|
+
else
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
# DO NOT ALLOW nil unix_domain_socket_path
|
31
|
+
# https://github.com/torvalds/linux/blob/master/include/uapi/linux/net.h#L47
|
32
|
+
#
|
33
|
+
def calculate_unix_domain_socket_status
|
34
|
+
# label in /proc/net/unix
|
35
|
+
# Num: RefCount Protocol Flags Type St Inode Path
|
36
|
+
paths = /^\w+: \d+ 00000000 \d+ \d+ (\d+) \d+ #{@unix_domain_socket_path}$/n
|
37
|
+
|
38
|
+
queued = 0
|
39
|
+
active = 0
|
40
|
+
# no point in pread since we can't stat for size on this file
|
41
|
+
::File.read(*[@proc_net_unix_path].push({encoding: 'binary'})).scan(paths) do |s|
|
42
|
+
case s[0].to_i
|
43
|
+
when 2 then queued += 1 # SS_CONNECTING
|
44
|
+
when 3 then active += 1 # SS_CONNECTED
|
45
|
+
end
|
46
|
+
end
|
47
|
+
{active: active, queued: queued, total: active + queued}.to_json
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rack-unix_domain_socket_status"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["SpringMT"]
|
9
|
+
spec.email = ["today.is.sky.blue.sky@gmail.com"]
|
10
|
+
spec.summary = %q{Check for unix domain socket usage}
|
11
|
+
spec.description = %q{Check for unix domain socket usage}
|
12
|
+
spec.homepage = "https://github.com/SpringMT/rack-unix_domain_socket_status"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'json'
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
|
4
|
+
describe Rack::UnixDomainSocketStatus do
|
5
|
+
app = lambda { |env|
|
6
|
+
[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
|
7
|
+
}
|
8
|
+
|
9
|
+
context 'confirm to Rack::Lint' do
|
10
|
+
subject do
|
11
|
+
Rack::Lint.new( Rack::UnixDomainSocketStatus.new(app, {unix_domain_socket_path: 'test.sock', proc_net_unix_path: 'tmp/dummy_unix'}) )
|
12
|
+
end
|
13
|
+
it do
|
14
|
+
response = Rack::MockRequest.new(subject).get('/')
|
15
|
+
expect(response.body).to eq 'Hello, World!'
|
16
|
+
end
|
17
|
+
it do
|
18
|
+
response = Rack::MockRequest.new(subject).get('/unix_status')
|
19
|
+
expect(response.body).to eq({active: 0, queued: 0, total: 0}.to_json)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'change path' do
|
24
|
+
subject do
|
25
|
+
Rack::Lint.new( Rack::UnixDomainSocketStatus.new(app, {unix_domain_socket_path: 'test.sock', proc_net_unix_path: 'tmp/dummy_unix', path: '/us'}) )
|
26
|
+
end
|
27
|
+
it do
|
28
|
+
response = Rack::MockRequest.new(subject).get('/us')
|
29
|
+
expect(response.body).to eq({active: 0, queued: 0, total: 0}.to_json)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'NOT exist proc_net_unix' do
|
34
|
+
subject do
|
35
|
+
Rack::Lint.new( Rack::UnixDomainSocketStatus.new(app, {unix_domain_socket_path: 'test.sock', proc_net_unix_path: 'tmp/hoge'}) )
|
36
|
+
end
|
37
|
+
it do
|
38
|
+
response = Rack::MockRequest.new(subject).get('/unix_status')
|
39
|
+
expect(response.body).to eq 'Hello, World!'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup(:default, :test)
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
|
5
|
+
require 'simplecov'
|
6
|
+
require 'simplecov-rcov'
|
7
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
$TESTING=true
|
11
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib/rack/')
|
12
|
+
require 'rack/unix_domain_socket_status'
|
13
|
+
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-unix_domain_socket_status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SpringMT
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Check for unix domain socket usage
|
42
|
+
email:
|
43
|
+
- today.is.sky.blue.sky@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/rack/unix_domain_socket_status.rb
|
54
|
+
- rack-unix_domain_socket_status.gemspec
|
55
|
+
- spec/rack-unix_domain_socket_status_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
homepage: https://github.com/SpringMT/rack-unix_domain_socket_status
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.2.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Check for unix domain socket usage
|
81
|
+
test_files:
|
82
|
+
- spec/rack-unix_domain_socket_status_spec.rb
|
83
|
+
- spec/spec_helper.rb
|