Skip to content

Instantly share code, notes, and snippets.

@softwhisper
Created March 11, 2012 16:17
Show Gist options
  • Save softwhisper/2016990 to your computer and use it in GitHub Desktop.
Save softwhisper/2016990 to your computer and use it in GitHub Desktop.
Capistrano receipt for general system status
namespace :status do
desc "Displays memory usage"
task :memory do
mem = capture("free -m | grep Mem").squeeze(" ").split(" ")[1..-1]
total, used, free, shared, buffers, cached = mem
puts "\nMemory in (MBs)"
puts "----------------------------"
puts "Total: #{total}"
puts "Used: #{used}"
puts "Free: #{free}"
puts "Shared: #{shared}"
puts "Buffers: #{buffers}"
puts "Cached: #{cached}"
puts "----------------------------\n\n"
end
end
# Output Example:
# ----------------------------
# Memory in (MBs)
# Total: 995
# Used: 648
# Free: 346
# Shared: 0
# Buffers: 93
# Cached: 207
----------------------------
@softwhisper
Copy link
Author

added squeeze(" ") to only clean spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment