memosig 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +8 -1
- data/VERSION +1 -1
- data/lib/memosig/app.rb +10 -34
- data/lib/memosig/matcher.rb +25 -0
- data/lib/memosig/output.rb +15 -0
- data/lib/memosig/version.rb +1 -1
- data/memosig.gemspec +13 -4
- data/spec/memosig/app_spec.rb +21 -0
- data/spec/memosig/proc_stat_spec.rb +26 -0
- data/spec/spec_helper.rb +8 -0
- metadata +43 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bc87039a61f8c2c0bb212eaf57f1b5a5927f1ea
|
4
|
+
data.tar.gz: 5fd57c20fcd76c16dcfbc8802cd5fcd4885996b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5dca2ffff020a990897f50950caee7fb004bc38e8a3610704232c4f2890206b5193c918b662413421ad26e6db459b2b6bcda6d41dacdc6bfb880309310d8cb
|
7
|
+
data.tar.gz: 37929e6cc0778ee32d0dc2d82f3ee4acea5d67c93f72357127fbdbbbb277ef2ed7c3153e286701af2431469ff342bdb0df559ed46c8070d8b3104d16ebf9ea38
|
data/Rakefile
CHANGED
@@ -11,13 +11,20 @@ GemHadar do
|
|
11
11
|
description 'This excecutable supervises the memory usage of processes, '\
|
12
12
|
'and sends a configurable signal to them if a configured limit '\
|
13
13
|
'is exceeded.'
|
14
|
-
test_dir '
|
14
|
+
test_dir 'spec'
|
15
15
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
|
16
16
|
'.AppleDouble'
|
17
17
|
readme 'README.md'
|
18
18
|
title "#{name.camelize}"
|
19
|
+
licenses << 'Apache-2.0'
|
20
|
+
|
21
|
+
executables << 'memosig'
|
19
22
|
|
20
23
|
dependency 'tins', '~>1.0'
|
21
24
|
dependency 'complex_config'
|
22
25
|
development_dependency 'rake'
|
26
|
+
development_dependency 'rspec'
|
27
|
+
development_dependency 'simplecov'
|
23
28
|
end
|
29
|
+
|
30
|
+
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/memosig/app.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'complex_config'
|
2
2
|
require 'memosig/proc_stat'
|
3
|
+
require 'memosig/output'
|
4
|
+
require 'memosig/matcher'
|
3
5
|
|
4
6
|
class Memosig::App
|
7
|
+
include Memosig::Output
|
8
|
+
|
5
9
|
def initialize(config: nil)
|
6
10
|
@config = ComplexConfig::Provider.config(config)
|
7
11
|
end
|
8
12
|
|
13
|
+
attr_reader :config
|
14
|
+
|
9
15
|
def run
|
10
16
|
check_memory
|
11
17
|
sleep (@config.wait_period || 300)
|
@@ -13,41 +19,11 @@ class Memosig::App
|
|
13
19
|
|
14
20
|
private
|
15
21
|
|
16
|
-
def process_prefix
|
17
|
-
"#{File.basename($0)} pid=#$$"
|
18
|
-
end
|
19
|
-
|
20
|
-
def output(message)
|
21
|
-
STDOUT.puts "#{process_prefix} #{message}"
|
22
|
-
STDOUT.flush
|
23
|
-
end
|
24
|
-
|
25
|
-
def error(message)
|
26
|
-
STDERR.puts "#{process_prefix} #{message}"
|
27
|
-
STDERR.flush
|
28
|
-
end
|
29
|
-
|
30
22
|
def check_memory_for(pattern, config, processes)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
output "restarting process pid=#{process.pid} "\
|
36
|
-
"pattern=#{pattern.source.inspect} "\
|
37
|
-
"rss #{process.rss}>#{config['rss_max']}"
|
38
|
-
Process.kill config['signal'], process.pid
|
39
|
-
else
|
40
|
-
output "no action on process pid=#{process.pid} "\
|
41
|
-
"pattern=#{pattern.source.inspect} "\
|
42
|
-
"rss #{process.rss}<=#{config['rss_max']}"
|
43
|
-
end
|
44
|
-
matched = true
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
unless matched
|
49
|
-
error "pattern #{pattern.source.inspect} didn't match any processes"
|
50
|
-
end
|
23
|
+
processes.any? do |process|
|
24
|
+
Memosig::Matcher.new(pattern, config).match? process
|
25
|
+
end and return
|
26
|
+
error "pattern #{pattern.source.inspect} didn't match any processes"
|
51
27
|
end
|
52
28
|
|
53
29
|
def check_memory
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'memosig/output'
|
2
|
+
|
3
|
+
class ::Memosig::Matcher
|
4
|
+
include Memosig::Output
|
5
|
+
|
6
|
+
def initialize(pattern, config)
|
7
|
+
@pattern, @config = pattern, config
|
8
|
+
end
|
9
|
+
|
10
|
+
def match?(process)
|
11
|
+
if process.command =~ @pattern
|
12
|
+
if process.rss > @config.rss_max
|
13
|
+
output "restarting process pid=#{process.pid} "\
|
14
|
+
"pattern=#{@pattern.source.inspect} "\
|
15
|
+
"rss #{process.rss}>#{@config.rss_max}"
|
16
|
+
Process.kill @config.signal, process.pid
|
17
|
+
else
|
18
|
+
output "no action on process pid=#{process.pid} "\
|
19
|
+
"pattern=#{@pattern.source.inspect} "\
|
20
|
+
"rss #{process.rss}<=#{@config.rss_max}"
|
21
|
+
end
|
22
|
+
matched = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Memosig::Output
|
2
|
+
def process_prefix
|
3
|
+
"#{File.basename($0)} pid=#$$"
|
4
|
+
end
|
5
|
+
|
6
|
+
def output(message)
|
7
|
+
STDOUT.puts "#{process_prefix} #{message}"
|
8
|
+
STDOUT.flush
|
9
|
+
end
|
10
|
+
|
11
|
+
def error(message)
|
12
|
+
STDERR.puts "#{process_prefix} #{message}"
|
13
|
+
STDERR.flush
|
14
|
+
end
|
15
|
+
end
|
data/lib/memosig/version.rb
CHANGED
data/memosig.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: memosig 0.0.
|
2
|
+
# stub: memosig 0.0.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "memosig"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
@@ -11,12 +11,15 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.date = "2015-03-13"
|
12
12
|
s.description = "This excecutable supervises the memory usage of processes, and sends a configurable signal to them if a configured limit is exceeded."
|
13
13
|
s.email = "flori@ping.de"
|
14
|
-
s.
|
15
|
-
s.
|
14
|
+
s.executables = ["memosig"]
|
15
|
+
s.extra_rdoc_files = ["README.md", "lib/memosig.rb", "lib/memosig/app.rb", "lib/memosig/matcher.rb", "lib/memosig/output.rb", "lib/memosig/proc_stat.rb", "lib/memosig/version.rb"]
|
16
|
+
s.files = [".gitignore", "COPYING", "Gemfile", "README.md", "Rakefile", "VERSION", "bin/memosig", "lib/memosig.rb", "lib/memosig/app.rb", "lib/memosig/matcher.rb", "lib/memosig/output.rb", "lib/memosig/proc_stat.rb", "lib/memosig/version.rb", "memosig.gemspec", "spec/assets/memosig.yml", "spec/memosig/app_spec.rb", "spec/memosig/proc_stat_spec.rb", "spec/spec_helper.rb"]
|
16
17
|
s.homepage = "http://flori.github.com/memosig"
|
18
|
+
s.licenses = ["Apache-2.0"]
|
17
19
|
s.rdoc_options = ["--title", "Memosig", "--main", "README.md"]
|
18
20
|
s.rubygems_version = "2.4.5"
|
19
21
|
s.summary = "Executable that supervises memory use of processes and signals them"
|
22
|
+
s.test_files = ["spec/memosig/app_spec.rb", "spec/memosig/proc_stat_spec.rb", "spec/spec_helper.rb"]
|
20
23
|
|
21
24
|
if s.respond_to? :specification_version then
|
22
25
|
s.specification_version = 4
|
@@ -24,17 +27,23 @@ Gem::Specification.new do |s|
|
|
24
27
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
28
|
s.add_development_dependency(%q<gem_hadar>, ["~> 1.0.0"])
|
26
29
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
31
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
27
32
|
s.add_runtime_dependency(%q<tins>, ["~> 1.0"])
|
28
33
|
s.add_runtime_dependency(%q<complex_config>, [">= 0"])
|
29
34
|
else
|
30
35
|
s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
|
31
36
|
s.add_dependency(%q<rake>, [">= 0"])
|
37
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
38
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
32
39
|
s.add_dependency(%q<tins>, ["~> 1.0"])
|
33
40
|
s.add_dependency(%q<complex_config>, [">= 0"])
|
34
41
|
end
|
35
42
|
else
|
36
43
|
s.add_dependency(%q<gem_hadar>, ["~> 1.0.0"])
|
37
44
|
s.add_dependency(%q<rake>, [">= 0"])
|
45
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
46
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
38
47
|
s.add_dependency(%q<tins>, ["~> 1.0"])
|
39
48
|
s.add_dependency(%q<complex_config>, [">= 0"])
|
40
49
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Memosig::App do
|
4
|
+
let :config do
|
5
|
+
'spec/assets/memosig.yml'
|
6
|
+
end
|
7
|
+
|
8
|
+
let :app do
|
9
|
+
Memosig::App.new(config: config)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'loads config' do
|
13
|
+
expect(app.config).to be_a ComplexConfig::Settings
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'checks the memory and sleeps if run' do
|
17
|
+
expect(app).to receive(:check_memory)
|
18
|
+
expect(app).to receive(:sleep)
|
19
|
+
app.run
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Memosig::ProcStat do
|
4
|
+
let :processes do
|
5
|
+
Memosig::ProcStat.all
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'gathers all process statistics' do
|
9
|
+
expect(processes.size).to be > 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'has a PID per line' do
|
13
|
+
expect(processes.first.pid).to be_a Integer
|
14
|
+
expect(processes.first.pid).to be > 0
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has a RSS per line' do
|
18
|
+
expect(processes.first.rss).to be_a Integer
|
19
|
+
expect(processes.first.rss).to be > 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has a command per line' do
|
23
|
+
expect(processes.first.command).to be_a String
|
24
|
+
expect(processes.first.command.size).to be > 0
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memosig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: tins
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,12 +97,15 @@ dependencies:
|
|
69
97
|
description: This excecutable supervises the memory usage of processes, and sends
|
70
98
|
a configurable signal to them if a configured limit is exceeded.
|
71
99
|
email: flori@ping.de
|
72
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- memosig
|
73
102
|
extensions: []
|
74
103
|
extra_rdoc_files:
|
75
104
|
- README.md
|
76
105
|
- lib/memosig.rb
|
77
106
|
- lib/memosig/app.rb
|
107
|
+
- lib/memosig/matcher.rb
|
108
|
+
- lib/memosig/output.rb
|
78
109
|
- lib/memosig/proc_stat.rb
|
79
110
|
- lib/memosig/version.rb
|
80
111
|
files:
|
@@ -87,13 +118,18 @@ files:
|
|
87
118
|
- bin/memosig
|
88
119
|
- lib/memosig.rb
|
89
120
|
- lib/memosig/app.rb
|
121
|
+
- lib/memosig/matcher.rb
|
122
|
+
- lib/memosig/output.rb
|
90
123
|
- lib/memosig/proc_stat.rb
|
91
124
|
- lib/memosig/version.rb
|
92
125
|
- memosig.gemspec
|
93
126
|
- spec/assets/memosig.yml
|
127
|
+
- spec/memosig/app_spec.rb
|
128
|
+
- spec/memosig/proc_stat_spec.rb
|
94
129
|
- spec/spec_helper.rb
|
95
130
|
homepage: http://flori.github.com/memosig
|
96
|
-
licenses:
|
131
|
+
licenses:
|
132
|
+
- Apache-2.0
|
97
133
|
metadata: {}
|
98
134
|
post_install_message:
|
99
135
|
rdoc_options:
|
@@ -119,4 +155,7 @@ rubygems_version: 2.4.5
|
|
119
155
|
signing_key:
|
120
156
|
specification_version: 4
|
121
157
|
summary: Executable that supervises memory use of processes and signals them
|
122
|
-
test_files:
|
158
|
+
test_files:
|
159
|
+
- spec/memosig/app_spec.rb
|
160
|
+
- spec/memosig/proc_stat_spec.rb
|
161
|
+
- spec/spec_helper.rb
|