stress_reporter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/bin/stress_reporter +14 -9
- data/lib/stress_reporter/actions/xmanager.rb +8 -5
- data/lib/stress_reporter/checker.rb +1 -1
- data/lib/stress_reporter/version.rb +1 -1
- data/stress_reporter.gemspec +2 -2
- metadata +6 -19
data/.gitignore
CHANGED
data/bin/stress_reporter
CHANGED
@@ -4,31 +4,35 @@ require 'stress_reporter'
|
|
4
4
|
require 'stress_reporter/checker'
|
5
5
|
require 'stress_reporter/actions/xmanager'
|
6
6
|
|
7
|
-
|
7
|
+
@_logger = Logger.new("/var/log/stress_report/monitor.log")
|
8
8
|
puts "Going to trigger when load average exceeds #{StressReporter::Checker::LIMIT}"
|
9
9
|
|
10
10
|
class MyTimeoutException < Exception ; end
|
11
11
|
|
12
|
+
# Initial delay between checks
|
12
13
|
@delay = 10.0;
|
13
14
|
|
15
|
+
def log severity, msg
|
16
|
+
@_logger.send severity, msg
|
17
|
+
puts "#{ severity }: #{ msg }"
|
18
|
+
end
|
19
|
+
|
20
|
+
|
14
21
|
while true do
|
15
22
|
begin
|
23
|
+
# Use custom exception so that we can treat it differenty
|
16
24
|
SystemTimer.timeout_after(StressReporter::TIMEOUT, MyTimeoutException) do
|
17
25
|
if StressReporter::Checker.go?
|
18
|
-
|
26
|
+
log(:warn, "Load average of #{ StressReporter::Checker::LIMIT } Exceeded: (#{ StressReporter::Checker.load_average }) - running checks")
|
19
27
|
StressReporter::Actions::Xmanager.report.each {|l|
|
20
|
-
|
21
|
-
puts line
|
22
|
-
logger.info line
|
28
|
+
log(:info, l)
|
23
29
|
}
|
24
30
|
end
|
25
31
|
end
|
26
32
|
@delay = @delay - 1.0
|
27
33
|
rescue MyTimeoutException
|
28
34
|
@delay = @delay * 2
|
29
|
-
|
30
|
-
logger.error msg
|
31
|
-
puts msg
|
35
|
+
log(:error, "Timeout Error executing checks and reporting, machine is trashing, doubling time between checks to #{ @delay }")
|
32
36
|
end
|
33
37
|
|
34
38
|
if @delay > 60.0
|
@@ -36,6 +40,7 @@ while true do
|
|
36
40
|
elsif @delay < 5.0
|
37
41
|
@delay = 5.0
|
38
42
|
end
|
39
|
-
|
43
|
+
log(:debug, "Sleeping for #@delay")
|
40
44
|
sleep @delay
|
41
45
|
end
|
46
|
+
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module StressReporter
|
2
2
|
module Actions
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# TODO:
|
3
|
+
# Actions to report on passenger usage.
|
4
|
+
# Current requests, urls, pids
|
5
|
+
# TODO: We should not assume that xm_last_url_for_{pid} are in /tmp
|
6
|
+
# TODO: Spawning passenger-status is slow
|
6
7
|
class Xmanager
|
7
8
|
|
8
9
|
CMD = "passenger-status"
|
9
10
|
PID_REGEX = /PID:\s*(\d+)/
|
10
11
|
|
11
|
-
# Report
|
12
|
+
# Report returns a string array
|
12
13
|
def self.report
|
13
14
|
out = []
|
14
15
|
Xmanager.current_requests.each_pair do |pid, url|
|
@@ -19,6 +20,7 @@ module StressReporter
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
23
|
+
# Returns array of pids of current passenger processes
|
22
24
|
def self.pids
|
23
25
|
pids = []
|
24
26
|
p = IO.popen(CMD)
|
@@ -30,13 +32,14 @@ module StressReporter
|
|
30
32
|
pids
|
31
33
|
end
|
32
34
|
|
35
|
+
# Returns hash { pid => url }
|
33
36
|
def self.current_requests
|
34
37
|
requests = {}
|
35
38
|
pids.each do |pid|
|
36
39
|
if File.exist?("/tmp/xm_last_url_for_#{pid}")
|
37
40
|
p = IO.popen("cat /tmp/xm_last_url_for_#{pid}")
|
38
41
|
while !p.eof?
|
39
|
-
requests[pid] = p.readpartial(1024)
|
42
|
+
requests[pid] = p.readpartial(1024).chomp
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
data/stress_reporter.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "stress_reporter"
|
8
8
|
gem.version = StressReporter::VERSION
|
9
9
|
gem.authors = ["Marcello Colacino", "Luca S.G. de Marinis"]
|
10
|
-
gem.email = ["loop23@gmail.com"]
|
10
|
+
gem.email = ["marcello.colacino@interact.it", "loop23@gmail.com"]
|
11
11
|
gem.description = %q{Daemon that runs and reports on stressful stuff}
|
12
12
|
gem.summary = %q{Was born with specific needs but may be extended to cover more scenarios}
|
13
13
|
gem.homepage = "https://github.com/InteractSpa/stress_reporter"
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_runtime_dependency 'sys-cpu'
|
21
|
-
gem.add_runtime_dependency 'passenger'
|
21
|
+
# gem.add_runtime_dependency 'passenger'
|
22
22
|
gem.add_runtime_dependency 'SystemTimer'
|
23
23
|
|
24
24
|
gem.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stress_reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcello Colacino
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
type: :runtime
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
prerelease: false
|
37
|
-
name:
|
37
|
+
name: SystemTimer
|
38
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
type: :runtime
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
prerelease: false
|
51
|
-
name:
|
51
|
+
name: rake
|
52
52
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
@@ -59,23 +59,10 @@ dependencies:
|
|
59
59
|
- 0
|
60
60
|
version: "0"
|
61
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
62
|
type: :development
|
77
63
|
description: Daemon that runs and reports on stressful stuff
|
78
64
|
email:
|
65
|
+
- marcello.colacino@interact.it
|
79
66
|
- loop23@gmail.com
|
80
67
|
executables:
|
81
68
|
- stress_reporter
|