Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jmazzi/645708 to your computer and use it in GitHub Desktop.

Select an option

Save jmazzi/645708 to your computer and use it in GitHub Desktop.
#!/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
@itspriddle
Copy link
Copy Markdown

Instead of grep Rails: | grep -v grep you can do grep "[R]ails:".

Don't remember why, but putting the first character in square brackets prevents the grep process itself from being returned.

@jmazzi
Copy link
Copy Markdown
Author

jmazzi commented Dec 28, 2010

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