rack-leakin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/lib/rack-leakin.rb +1 -0
- data/lib/rack/leakin.rb +47 -0
- data/lib/rack/leakin/version.rb +9 -0
- data/rack-memory.gemspec +21 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Dimko
|
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,37 @@
|
|
1
|
+
# Rack::Leakin
|
2
|
+
|
3
|
+
Rack middleware that detect and handle memory leaks
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rack-leakin'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then, if you are using Rails, simply add to initializer:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Rails.application.config.middleware.use Rack::Leakin
|
17
|
+
```
|
18
|
+
|
19
|
+
You can set threshold in kilobytes and the handler:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Rack::Leakin.threshold = 131072 # default, 128MB
|
23
|
+
```
|
24
|
+
|
25
|
+
For example, it may be useful to send exceptions to Airbrake:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Rack::Leakin.handler = lambda do |env, beginning, ending|
|
29
|
+
Airbrake.notify \
|
30
|
+
:error_message => "Memory leak detected, from #{from}KB to #{to}KB",
|
31
|
+
:error_class => 'MemoryLeak',
|
32
|
+
:parameters => {
|
33
|
+
:request_uri => env['REQUEST_URI'],
|
34
|
+
:method => env['REQUEST_METHOD']
|
35
|
+
}
|
36
|
+
end
|
37
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/rack-leakin.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/leakin'
|
data/lib/rack/leakin.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'process_memory'
|
2
|
+
require 'rack/leakin/version'
|
3
|
+
require 'rack'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
class Leakin
|
7
|
+
class << self
|
8
|
+
attr_writer :threshold, :handler, :logger
|
9
|
+
|
10
|
+
def threshold
|
11
|
+
@threshold ||= 131072 # 128 Mb by default
|
12
|
+
end
|
13
|
+
|
14
|
+
def handler
|
15
|
+
@handler ||= lambda do |env, beginning, ending|
|
16
|
+
logger.warn "*** [Memory leak detected] #{env['REQUEST_METHOD']} #{env['REQUEST_URI']}, #{beginning}KB --> #{ending}KB"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def logger
|
21
|
+
@logger ||= begin
|
22
|
+
if defined?(Rails)
|
23
|
+
::Rails.logger
|
24
|
+
else
|
25
|
+
::Logger.new('rack-leaker.log')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(app)
|
32
|
+
@app = app
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(env)
|
36
|
+
beginning = Process.memory
|
37
|
+
|
38
|
+
@app.call(env).tap do
|
39
|
+
ending = Process.memory
|
40
|
+
|
41
|
+
if ending - beginning > self.class.threshold
|
42
|
+
self.class.handler.call(env, beginning, ending)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/rack-memory.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/leakin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'rack-leakin'
|
8
|
+
gem.version = Rack::Leakin::VERSION
|
9
|
+
gem.authors = ['Dimko']
|
10
|
+
gem.email = ['deemox@gmail.com']
|
11
|
+
gem.description = %q{Rack middleware that detect and handle memory leaks}
|
12
|
+
gem.summary = %q{Rack middleware that detect and handle memory leaks}
|
13
|
+
gem.homepage = ''
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_dependency 'rack'
|
20
|
+
gem.add_dependency 'process_memory'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-leakin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dimko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: process_memory
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Rack middleware that detect and handle memory leaks
|
47
|
+
email:
|
48
|
+
- deemox@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/rack-leakin.rb
|
59
|
+
- lib/rack/leakin.rb
|
60
|
+
- lib/rack/leakin/version.rb
|
61
|
+
- rack-memory.gemspec
|
62
|
+
homepage: ''
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.24
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Rack middleware that detect and handle memory leaks
|
86
|
+
test_files: []
|