stress_reporter 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.
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/bin/stress_reporter +41 -0
- data/lib/stress_reporter/actions/xmanager.rb +48 -0
- data/lib/stress_reporter/checker.rb +26 -0
- data/lib/stress_reporter/version.rb +3 -0
- data/lib/stress_reporter.rb +11 -0
- data/stress_reporter.gemspec +26 -0
- data/test/test_checker.rb +17 -0
- metadata +133 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Luca S.G. de Marinis
|
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,32 @@
|
|
1
|
+
# StressReporter
|
2
|
+
|
3
|
+
Daemon that runs and reports on stressful stuff.
|
4
|
+
Was born with specific needs but may be extended to cover more scenarios.
|
5
|
+
Should help in understanding why a machine deserves to die.
|
6
|
+
|
7
|
+
## Notice
|
8
|
+
|
9
|
+
See the version number? 0.0.1 - this is pre pre pre alpha, don't even
|
10
|
+
think about using it in production.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
$ gem install stress_reporter
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
stress_reporter [avg]
|
19
|
+
|
20
|
+
avg defaults to 1.0
|
21
|
+
If load average exceeds avg, runs various checks (well, not that various
|
22
|
+
for the time being, just a passenger-status specific one), and logs to
|
23
|
+
/tmp/xxxx
|
24
|
+
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/stress_reporter
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'stress_reporter'
|
4
|
+
require 'stress_reporter/checker'
|
5
|
+
require 'stress_reporter/actions/xmanager'
|
6
|
+
|
7
|
+
logger = Logger.new("/tmp/check_senato_status_#{Time.now.strftime('%Y.%d.%m')}.log")
|
8
|
+
puts "Going to trigger when load average exceeds #{StressReporter::Checker::LIMIT}"
|
9
|
+
|
10
|
+
class MyTimeoutException < Exception ; end
|
11
|
+
|
12
|
+
@delay = 10.0;
|
13
|
+
|
14
|
+
while true do
|
15
|
+
begin
|
16
|
+
SystemTimer.timeout_after(StressReporter::TIMEOUT, MyTimeoutException) do
|
17
|
+
if StressReporter::Checker.go?
|
18
|
+
puts "Ecceduto!"
|
19
|
+
StressReporter::Actions::Xmanager.report.each {|l|
|
20
|
+
line = "#{Time.now.strftime('%Y/%d/%m %H:%M:%S')}\t#{StressReporter::Checker.load_average}\t#{ line }"
|
21
|
+
puts line
|
22
|
+
logger.info line
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@delay = @delay - 1.0
|
27
|
+
rescue MyTimeoutException
|
28
|
+
@delay = @delay * 2
|
29
|
+
msg = "#{Time.now.strftime('%Y/%d/%m %H:%M:%S')} Timeout Error executing checks and reporting, doubling time between checks"
|
30
|
+
logger.error msg
|
31
|
+
puts msg
|
32
|
+
end
|
33
|
+
|
34
|
+
if @delay > 60.0
|
35
|
+
@delay = 60.0
|
36
|
+
elsif @delay < 5.0
|
37
|
+
@delay = 5.0
|
38
|
+
end
|
39
|
+
puts "Sleeping for #@delay"
|
40
|
+
sleep @delay
|
41
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module StressReporter
|
2
|
+
module Actions
|
3
|
+
# Azioni da intraprendere per reportare sullo stato di xmanager.
|
4
|
+
# Richieste correnti, loro url, pid etc.
|
5
|
+
# TODO: Non assumere che i files xm_last_url_for_{pid} siano in /tmp
|
6
|
+
class Xmanager
|
7
|
+
|
8
|
+
CMD = "passenger-status"
|
9
|
+
PID_REGEX = /PID:\s*(\d+)/
|
10
|
+
|
11
|
+
# Report torna un array di stringhe
|
12
|
+
def self.report
|
13
|
+
out = []
|
14
|
+
Xmanager.current_requests.each_pair do |pid, url|
|
15
|
+
out << "PID:\t#{ pid }\tREQUEST:\t#{ url }"
|
16
|
+
end
|
17
|
+
out
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.pids
|
23
|
+
pids = []
|
24
|
+
p = IO.popen(CMD)
|
25
|
+
while !p.eof?
|
26
|
+
line = p.readpartial(1024)
|
27
|
+
m = line.scan PID_REGEX
|
28
|
+
pids = m.flatten
|
29
|
+
end
|
30
|
+
pids
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.current_requests
|
34
|
+
requests = {}
|
35
|
+
pids.each do |pid|
|
36
|
+
if File.exist?("/tmp/xm_last_url_for_#{pid}")
|
37
|
+
p = IO.popen("cat /tmp/xm_last_url_for_#{pid}")
|
38
|
+
while !p.eof?
|
39
|
+
requests[pid] = p.readpartial(1024)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
requests
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This class has the knowledge of when to run the reporting.
|
2
|
+
# It may well become a strategy, or a DSL parser; for the time
|
3
|
+
# being the check is very crude, just check last minute load
|
4
|
+
# average
|
5
|
+
class StressReporter::Checker
|
6
|
+
|
7
|
+
# This limit is going to be passed in as a command line arg
|
8
|
+
# Defaults to 1.0
|
9
|
+
LIMIT = ARGV.empty? ? 1 : ARGV[0].to_f
|
10
|
+
|
11
|
+
# starts at 0.0
|
12
|
+
@@load_average = 0.0
|
13
|
+
|
14
|
+
# Returns true if limit exceeded. Sets @@load_average
|
15
|
+
def self.go?
|
16
|
+
@@load_average = Sys::CPU.load_avg[0]
|
17
|
+
@@load_average > LIMIT
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns last load average
|
21
|
+
def self.load_average
|
22
|
+
@@load_average
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stress_reporter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "stress_reporter"
|
8
|
+
gem.version = StressReporter::VERSION
|
9
|
+
gem.authors = ["Marcello Colacino", "Luca S.G. de Marinis"]
|
10
|
+
gem.email = ["loop23@gmail.com"]
|
11
|
+
gem.description = %q{Daemon that runs and reports on stressful stuff}
|
12
|
+
gem.summary = %q{Was born with specific needs but may be extended to cover more scenarios}
|
13
|
+
gem.homepage = "https://github.com/InteractSpa/stress_reporter"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'sys-cpu'
|
21
|
+
gem.add_runtime_dependency 'passenger'
|
22
|
+
gem.add_runtime_dependency 'SystemTimer'
|
23
|
+
|
24
|
+
gem.add_development_dependency 'rake'
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'stress_reporter'
|
5
|
+
require 'stress_reporter/checker'
|
6
|
+
|
7
|
+
class CheckerTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def test_average
|
10
|
+
# All'inizio e' 0.0
|
11
|
+
assert_equal 0.0, StressReporter::Checker.load_average
|
12
|
+
StressReporter::Checker.go?
|
13
|
+
# Poi presumibilmente no
|
14
|
+
assert StressReporter::Checker.load_average > 0.0
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stress_reporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Marcello Colacino
|
14
|
+
- Luca S.G. de Marinis
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2012-10-23 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
name: sys-cpu
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
requirement: *id001
|
34
|
+
type: :runtime
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
name: passenger
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
requirement: *id002
|
48
|
+
type: :runtime
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
prerelease: false
|
51
|
+
name: SystemTimer
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirement: *id003
|
62
|
+
type: :runtime
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
prerelease: false
|
65
|
+
name: rake
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirement: *id004
|
76
|
+
type: :development
|
77
|
+
description: Daemon that runs and reports on stressful stuff
|
78
|
+
email:
|
79
|
+
- loop23@gmail.com
|
80
|
+
executables:
|
81
|
+
- stress_reporter
|
82
|
+
extensions: []
|
83
|
+
|
84
|
+
extra_rdoc_files: []
|
85
|
+
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- bin/stress_reporter
|
93
|
+
- lib/stress_reporter.rb
|
94
|
+
- lib/stress_reporter/actions/xmanager.rb
|
95
|
+
- lib/stress_reporter/checker.rb
|
96
|
+
- lib/stress_reporter/version.rb
|
97
|
+
- stress_reporter.gemspec
|
98
|
+
- test/test_checker.rb
|
99
|
+
homepage: https://github.com/InteractSpa/stress_reporter
|
100
|
+
licenses: []
|
101
|
+
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 1.8.24
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: Was born with specific needs but may be extended to cover more scenarios
|
132
|
+
test_files:
|
133
|
+
- test/test_checker.rb
|