Skip to content

Instantly share code, notes, and snippets.

@jakimowicz
Created August 25, 2010 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakimowicz/550476 to your computer and use it in GitHub Desktop.
Save jakimowicz/550476 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def output_config
puts <<-END
graph_category passenger
graph_title memory
graph_vlabel megabytes
graph_info This graph shows the memory consumption made by passenger processes, passenger and nginx.
graph_order nginx passenger rails
rails.label rails
rails.draw AREA
rails.info Total memory used by all rails processes.
passenger.label passenger
passenger.draw AREA
passenger.info Total memory used by passenger.
nginx.label nginx
nginx.draw AREA
nginx.info Total memory used by nginx.
END
exit 0
end
def total_for(component, str)
str.scan(/\d+\s+\d+.\d+ MB\s+(\d+.\d+) MB\s+#{component}/).flatten.collect(&:to_f).inject(:+)
end
def output_values
stats = `sudo passenger-memory-stats`
unless $?.success?
$stderr.puts "failed executing passenger-memory-stats"
exit 1
end
puts "rails.value #{total_for 'Rails', stats}",
"passenger.value #{total_for 'Passenger', stats}",
"nginx.value #{total_for 'nginx', stats}"
end
if ARGV[0] == "config"
output_config
else
output_values
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment