weasel-the-memory-watcher 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/Gemfile +4 -2
- data/LICENSE +12 -17
- data/README.rdoc +17 -12
- data/Rakefile +0 -9
- data/VERSION +1 -1
- data/bin/weasel +2 -0
- data/lib/memory_watch.rb +4 -8
- data/test/helper.rb +2 -5
- data/test/test_memory_watch.rb +17 -15
- metadata +52 -79
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use
|
1
|
+
rvm use 1.9.3-p327@memory_watch --create
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,20 +1,15 @@
|
|
1
|
-
Copyright (c) 2009 Curtis Schofield
|
2
1
|
|
3
|
-
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
2
|
+
Copyright (C) 2009,2010 Curtis Schofield
|
10
3
|
|
11
|
-
|
12
|
-
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
MERCHANTABILITY
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README.rdoc
CHANGED
@@ -1,17 +1,22 @@
|
|
1
|
-
=
|
1
|
+
= Weasel
|
2
2
|
|
3
|
-
|
3
|
+
Simple memory monitor - used in production with passenger to limit uptime of a service using excessive memory - as happens with ruby-1.8.7 on non ree projects
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
5
|
+
see ./bin/weasel for all the arguments that it takes
|
14
6
|
|
15
|
-
|
7
|
+
= Example
|
8
|
+
|
9
|
+
weasel --callback "%x{kill -USR1 #{pid.to_s}}" --watch 'Rails:' --num-cycles 3 --num-over-marks 2 --callback-message 'sending SIGUSR1' --high-water-mb 440 --delay 1
|
10
|
+
|
11
|
+
the above will send sigusr1 (graceful exit) to all the processes matching 'Rails' that run over 440MB 2 out of 3
|
12
|
+
samples.
|
13
|
+
|
14
|
+
Samples are taken a total of 3 times with a delay of 1 second between them.
|
15
|
+
|
16
|
+
Put this in a cronjob to run every minute and you have a very simple, robust way to reap overmemory processes.
|
17
|
+
|
18
|
+
You can also combine this nicely with services that use daemontools if you don't want to write complex restart / shutdown code.
|
19
|
+
|
20
|
+
= Fin
|
16
21
|
|
17
22
|
Copyright (c) 2010 Curtis Schofield. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -47,12 +47,3 @@ task :test => :check_dependencies
|
|
47
47
|
|
48
48
|
task :default => :test
|
49
49
|
|
50
|
-
require 'rake/rdoctask'
|
51
|
-
Rake::RDocTask.new do |rdoc|
|
52
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "weasel #{version}"
|
56
|
-
rdoc.rdoc_files.include('README*')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/bin/weasel
CHANGED
data/lib/memory_watch.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
|
2
1
|
class MemoryWatch
|
3
2
|
attr_accessor :watch_string,:high_water_pids,:callback,:high_water_mb,
|
4
3
|
:delay,:num_cycles,:num_over_marks,:pids,:callback_message
|
5
4
|
|
6
5
|
def initialize(options)
|
7
|
-
self.callback = options[:callback] ||
|
8
|
-
|
9
|
-
self.
|
10
|
-
"Callback Triggered").strip
|
11
|
-
self.watch_string = (options[:watch] ||
|
12
|
-
"this poem is a pomme").strip
|
6
|
+
self.callback = options[:callback] || lambda {|pid| p pid}
|
7
|
+
self.callback_message = (options[:callback_message] || "Callback Triggered").strip
|
8
|
+
self.watch_string = Regexp.escape((options[:watch] || "this poem is a pomme").strip)
|
13
9
|
self.delay = options[:delay] || 60
|
14
10
|
self.num_cycles = options[:num_cycles] || 3
|
15
11
|
self.num_over_marks = options[:num_over_marks] || 2
|
@@ -43,7 +39,7 @@ class MemoryWatch
|
|
43
39
|
_run.each { |pid|
|
44
40
|
memory_usage = %x{ps -o rss= -p #{pid}}.to_i # KB
|
45
41
|
if memory_usage > self.high_water_mb * 1024 # 750MB
|
46
|
-
puts "WARNING - Process #{pid} hit high water mark"
|
42
|
+
puts "WARNING - Process #{pid} hit high water mark at #{memory_usage / 1024}MB"
|
47
43
|
self.high_water_pids[pid] ||= []
|
48
44
|
self.high_water_pids[pid] << memory_usage
|
49
45
|
end
|
data/test/helper.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
2
3
|
require 'test/unit'
|
3
|
-
require "bundler/setup"
|
4
|
-
require 'wrong/adapters/test_unit'
|
5
4
|
|
6
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
6
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
7
|
require 'memory_watch'
|
9
|
-
|
10
|
-
class Test::Unit::TestCase
|
11
|
-
end
|
8
|
+
class Test::Unit::TestCase; end
|
data/test/test_memory_watch.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
require 'helper'
|
2
2
|
class TestMemoryWatch < Test::Unit::TestCase
|
3
|
-
def
|
4
|
-
cmd = %q{ruby ./bin/weasel --delay 999999 --num_cycles 9900000099}
|
5
|
-
pid = fork { %x{#{cmd}} }
|
3
|
+
def setup
|
4
|
+
@cmd = %q{ruby ./bin/weasel --delay 999999 --num_cycles 9900000099}
|
5
|
+
pid = fork { %x{#{@cmd}} }
|
6
6
|
Process.detach(pid)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
wm.pids.each do |pid|
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@wm.pids.each do |pid|
|
13
11
|
%x{kill -9 #{pid}}
|
14
12
|
end
|
15
13
|
end
|
14
|
+
|
15
|
+
def test_watches_self
|
16
|
+
@wm = MemoryWatch.new(:watch => @cmd , :high_water_mb => 0.02,:delay => 0.1, :num_cycles => 1)
|
17
|
+
@wm.cycle
|
18
|
+
assert_equal 1, @wm.high_water_pids.size
|
19
|
+
end
|
20
|
+
|
16
21
|
def test_runs_callback
|
17
22
|
test_magiggy = false
|
18
|
-
wm = MemoryWatch.new(:watch =>
|
23
|
+
@wm = MemoryWatch.new(:watch => @cmd,
|
19
24
|
:high_water_mb => 0,
|
20
25
|
:num_cycles => 1,
|
21
26
|
:delay => 0.01,
|
@@ -24,10 +29,7 @@ class TestMemoryWatch < Test::Unit::TestCase
|
|
24
29
|
test_magiggy = pid
|
25
30
|
},
|
26
31
|
:callback_message => 'Message')
|
27
|
-
wm.cycle
|
28
|
-
|
29
|
-
wm.high_water_pids.include? test_magiggy
|
30
|
-
}
|
32
|
+
@wm.cycle
|
33
|
+
assert_includes @wm.high_water_pids, test_magiggy
|
31
34
|
end
|
32
35
|
end
|
33
|
-
|
metadata
CHANGED
@@ -1,76 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: weasel-the-memory-watcher
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 1.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Curtis Schofield
|
14
9
|
- www.goodreads.com
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dependencies:
|
22
|
-
- !ruby/object:Gem::Dependency
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
name: wrong
|
26
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
|
-
requirements:
|
29
|
-
- - ">="
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
hash: 3
|
32
|
-
segments:
|
33
|
-
- 0
|
34
|
-
version: "0"
|
35
|
-
requirement: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
13
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
39
16
|
name: jeweler
|
40
|
-
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
41
18
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
version: "0"
|
49
|
-
requirement: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
51
23
|
type: :development
|
52
24
|
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
53
32
|
name: bundler
|
54
|
-
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
55
34
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
64
47
|
description: Dedicated to my dead cat and goodreads.com
|
65
48
|
email: github.com@robotarmyma.de
|
66
|
-
executables:
|
49
|
+
executables:
|
67
50
|
- weasel
|
68
51
|
extensions: []
|
69
|
-
|
70
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
71
53
|
- LICENSE
|
72
54
|
- README.rdoc
|
73
|
-
files:
|
55
|
+
files:
|
74
56
|
- .document
|
75
57
|
- .rvmrc
|
76
58
|
- Gemfile
|
@@ -83,40 +65,31 @@ files:
|
|
83
65
|
- lib/weasel.rb
|
84
66
|
- test/helper.rb
|
85
67
|
- test/test_memory_watch.rb
|
86
|
-
has_rdoc: true
|
87
68
|
homepage: http://github.com/robotarmy/weasel
|
88
69
|
licenses: []
|
89
|
-
|
90
70
|
post_install_message:
|
91
71
|
rdoc_options: []
|
92
|
-
|
93
|
-
require_paths:
|
72
|
+
require_paths:
|
94
73
|
- lib
|
95
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
75
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
segments:
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
segments:
|
102
81
|
- 0
|
103
|
-
|
104
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
hash: 686863708920555186
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
84
|
none: false
|
106
|
-
requirements:
|
107
|
-
- -
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
|
110
|
-
segments:
|
111
|
-
- 0
|
112
|
-
version: "0"
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
113
89
|
requirements: []
|
114
|
-
|
115
90
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.
|
91
|
+
rubygems_version: 1.8.24
|
117
92
|
signing_key:
|
118
93
|
specification_version: 3
|
119
|
-
summary:
|
120
|
-
test_files:
|
121
|
-
- test/helper.rb
|
122
|
-
- test/test_memory_watch.rb
|
94
|
+
summary: ! 'Weasel : The memory wacher'
|
95
|
+
test_files: []
|