Skip to content

Instantly share code, notes, and snippets.

@jakimowicz
Created August 25, 2010 23:10
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/550478 to your computer and use it in GitHub Desktop.
Save jakimowicz/550478 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def output_config
puts <<-END
graph_category passenger
graph_title rails processes memory
graph_vlabel megabytes
graph_info This graph shows the average, min and max memory consumption made by rails processes.
graph_order max average min
max.label max
max.draw AREA
max.info Top memory consomption by a rails process.
min.label min
min.draw AREA
min.info Memory used by the application min (minimum memory consumption).
average.label average
average.draw AREA
average.info average memory consummed by all rails processes.
END
exit 0
end
def output_values
stats = `sudo passenger-memory-stats`
unless $?.success?
$stderr.puts "failed executing passenger-memory-stats"
exit 1
end
rails_processes = stats.scan(/\d+\s+\d+.\d+ MB\s+(\d+.\d+) MB\s+Rails/).flatten.collect(&:to_f)
puts "max.value #{rails_processes.max}"
puts "average.value #{rails_processes.inject(:+) / rails_processes.length.to_f}"
puts "min.value #{rails_processes.min}"
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