passenger_mon 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +42 -0
  3. data/bin/passenger_mon +19 -11
  4. metadata +7 -5
  5. data/README +0 -26
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alex Sharp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
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:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ ## tl;dr ##
2
+
3
+ Simple rails process monitoring for passenger 3.
4
+
5
+ ## Usage ##
6
+
7
+ **IMPORTANT:** passenger_mon needs to be run as root to properly get access to Passenger's
8
+ `passenger-memory-stats` output.
9
+
10
+ # Check for out of control processes every 10 seconds
11
+ sudo passenger_mon --interval=10
12
+
13
+ # Check every 30 seconds for processes exceeding 500mb of memory
14
+ sudo passenger_mon --interval=30 --memory=500
15
+
16
+ # Specify a pidfile
17
+ sudo passenger_mon --pid=tmp/passenger_mon.pid
18
+
19
+ # Specify a logfile
20
+ sudo passenger_mon --log=log/passenger_mon.log
21
+
22
+ ## Description ##
23
+
24
+ A primary aim of this script is to have a very tiny memory footprint itself.
25
+ It is a very lightweight script that is intended to be run by root as a daemon.
26
+
27
+ It works by running in a continuous loop, sleeping for the specified interval,
28
+ and parsing the output of `passenger-memory-stats` to find processes that have
29
+ crossed the specified memory threshold (the default is 400 MB).
30
+
31
+ ## Problem ##
32
+
33
+ Currently, Passenger 3 (and previous versions) don't generate pidfiles or the
34
+ application processes it spawns. This makes it very difficult to monitor these
35
+ processes with tools like monit and [god](http://github.com/mojombo/god). Further
36
+ compounding this problem is the lack of any sort of per process memory threshold
37
+ for passenger.
38
+
39
+ ## Contributors
40
+
41
+ * Rick Bradley
42
+ * Alex Sharp
data/bin/passenger_mon CHANGED
@@ -8,46 +8,54 @@ options = {}
8
8
  op = OptionParser.new do |opts|
9
9
  opts.banner = 'Usage: passenger_mon [options]'
10
10
 
11
- opts.on("-i=SECONDS", "--interval=SECONDS", "Poll interval in seconds (default: 10)") do |interval|
11
+ opts.on("-i=SECONDS", "--interval=SECONDS", "Poll interval in seconds (default: 30)") do |interval|
12
12
  options[:interval] = interval
13
13
  end
14
14
 
15
- opts.on("-m=MEMORY", "--memory=MB", "Memory threshold in MB (default: 800)") do |mb|
15
+ opts.on("-m=MEMORY", "--memory=MB", "Memory threshold in MB (default: 400)") do |mb|
16
16
  options[:threshold] = mb
17
17
  end
18
18
 
19
+ opts.on("-l=LOG_FILE", "--log=LOG_FILE", "Log file location (default: /var/log/passenger_mon.log)") do |log|
20
+ options[:log] = log
21
+ end
22
+
23
+ opts.on("-p=PIDFILE", "--pid=PID_FILE", "Pidfile to write") do |pidfile|
24
+ options[:pidfile] = pidfile
25
+ end
26
+
19
27
  opts.on_tail("-h", "--help", "show this message") do
20
28
  abort(opts.to_s)
21
29
  end
22
30
  end.parse!
23
31
 
24
32
  # set option defaults
25
- options[:interval] ||= 10
26
- options[:threshold] ||= 800
33
+ options[:interval] ||= 30
34
+ options[:threshold] ||= 400
35
+ options[:log] ||= "/var/log/passenger_mong.log"
36
+ options[:pidfile] ||= "/tmp/passenger_mon.pid"
27
37
  options[:threshold] = options[:threshold].to_i
28
38
 
29
- process_name = 'passenger_mon'
30
- pidfile = "/tmp/#{process_name}.pid"
31
39
 
32
40
  # If a pidfile exists when we start up, we need to remove it.
33
41
  # This probably means a non-clean shutdown the last time
34
42
  # the program was shutdown.
35
- if File.exist?(pidfile)
43
+ if File.exist?(options[:pidfile])
36
44
  $stdout.puts "Existing pidfile found. Removing..."
37
- FileUtils.rm(pidfile)
45
+ FileUtils.rm(options[:pidfile])
38
46
  end
39
47
 
40
48
  # remove the pidfile on shutdown
41
49
  at_exit do
42
50
  $stdout.puts "Removing pidfile."
43
- FileUtils.rm(pidfile)
51
+ FileUtils.rm(options[:pidfile])
44
52
  end
45
53
 
46
54
  # write out the pidfile
47
- File.open(pidfile, 'w') { |f| f.puts($$) }
55
+ File.open(options[:pidfile], 'w') { |f| f.puts($$) }
48
56
 
49
57
  require 'logger'
50
- logger = Logger.new("/var/log/passenger_mon.log")
58
+ logger = Logger.new(options[:log])
51
59
 
52
60
  Signal.trap('INT') do
53
61
  logger.info "Shutting down now..."
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passenger_mon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Sharp
@@ -28,9 +28,11 @@ executables:
28
28
  extensions: []
29
29
 
30
30
  extra_rdoc_files:
31
- - README
31
+ - README.md
32
+ - MIT-LICENSE
32
33
  files:
33
- - README
34
+ - README.md
35
+ - MIT-LICENSE
34
36
  - bin/passenger_mon
35
37
  has_rdoc: true
36
38
  homepage: https://github.com/ajsharp/passenger_mon
data/README DELETED
@@ -1,26 +0,0 @@
1
- ## tl;dr ##
2
-
3
- Simple rails process monitoring for passenger 3.
4
-
5
- ## Usage ##
6
-
7
- passenger_mon needs to be run as root to properly get access to Passenger's
8
- `passenger-memory-stats` output.
9
-
10
- # Check for out of control processes every 10 seconds
11
- sudo passenger_mon --interval=10
12
-
13
-
14
- ## Problem
15
-
16
- Currently, Passenger 3 (and previous versions) don't generate pidfiles or the
17
- application processes it spawns. This makes it very difficult to monitor these
18
- processes with tools like monit and [god](http://github.com/mojombo/god). Further
19
- compounding this problem is the lack of any sort of per process memory threshold
20
- for passenger.
21
-
22
-
23
- ## Contributors
24
-
25
- * Rick Bradley
26
- * Alex Sharp