Forked from jamiew/Munin Passenger Phusion Memory Stats.rb
Created
October 25, 2010 20:39
-
-
Save jmazzi/645708 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 | |
| def output_config | |
| puts <<-END | |
| graph_category App | |
| graph_title Passenger memory stats | |
| graph_vlabel count | |
| memory.label memory | |
| END | |
| exit 0 | |
| end | |
| def output_values | |
| # passenger-memory-stats does a ps for 'Rails:'. If you | |
| # don't 'grep -v grep' it shows as another Rails process | |
| status = `/usr/local/bin/passenger-memory-stats | grep Rails: |grep -v grep` | |
| total_mem = 0.0 | |
| unless $?.success? | |
| $stderr.puts "failed executing passenger-memory-stats" | |
| exit 1 | |
| end | |
| status.split("\n").each do |line| | |
| if line=~ /Rails:/ | |
| pid, mem, mb, wha, rails, path = line.split("\s") | |
| total_mem += mem.to_f | |
| end | |
| end | |
| puts "memory.value #{total_mem * 1024.0}" | |
| end | |
| if ARGV[0] == "config" | |
| output_config | |
| else | |
| output_values | |
| end |
Author
The regex [R] matches a character set which only has one letter, R, and the literal string "ails:". grep won't match the original regular expression string, as it also includes the square brackets and treats it as literal :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of
grep Rails: | grep -v grepyou can dogrep "[R]ails:".Don't remember why, but putting the first character in square brackets prevents the grep process itself from being returned.