Created
September 15, 2009 21:51
-
-
Save skinandbones/187676 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env ruby | |
| MEMORY_LIMIT = 300 | |
| # Parse output like this | |
| # --------- Passenger processes ---------- | |
| # PID Threads VMSize Private Name | |
| # ---------------------------------------- | |
| # 1942 27 24.0 MB 1.1 MB PassengerNginxHelperServer /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.5 /opt/ruby-enterprise/bin/ruby 3 4 0 6 0 0 1 nobody 33 33 /tmp/passenger.1939 | |
| # 1957 1 71.0 MB 10.5 MB Passenger spawn server | |
| # 1992 1 291.5 MB 47.1 MB Passenger ApplicationSpawner: /data/otc_staging/current | |
| # 1997 1 369.7 MB 120.1 MB Rails: /data/otc_staging/current | |
| status = `/opt/ruby-enterprise/bin/passenger-memory-stats` | |
| status.split("\n").each do |line| | |
| if match = line.match(/(\d+)\s+\d+\s+\d+\.\d\s+MB\s+(\d+)\.\d\s+MB\s+Rails:/) | |
| Process.kill("ABRT", match[1].to_i) if match[2].to_i > MEMORY_LIMIT | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment