How To Display Linux VPS Memory Usage

In my experience, the hardest thing to work around when using a VPS for hosting is limited memory. It’s definitely a challenge to try and tune a database, web server, and application server for load under the constraints of a VPS plan (typically 512 MB or less of RAM). The best solution I came-up with was to use a baseline of about 70% of my guaranteed memory quota when the various servers started up, with 30% of my guaranteed memory free for high traffic situations. This seems to be working for me pretty well so far, especially considering that my memory usage can theoretically temporarily burst to 300% of my guaranteed memory quota.

However hosting in a VPS can present some challenges when trying to determine load and memory usage for your VPS. For instance, when using top, the memory statistics displayed represent the whole server and not your VPS. That said, I’ve only found one way to get an idea of what my memory usage is, how much I have reserved, and how much my VPS is allowed to burst to via command line is this script:

  1. #!/bin/bash
  2. bean=`cat /proc/user_beancounters`
  3. guar=`echo “$bean” | grep vmguar | awk ‘{ print $4;}’`
  4. burst=`echo “$bean” | grep privvm | awk ‘{ print $5;}’`
  5. priv=`echo “$bean” | grep privvm | awk ‘{ print $2;}’`
  6. let total=guar/256
  7. let used=priv/256
  8. let burst=burst/256
  9. echo “VPS memory usage:”
  10. echo “Used: $used MB”
  11. echo “Total: $total MB”
  12. echo “Burstable to: $burst MB”

As far as I know this should work under any Virtuozzo Linux based virtual private server, but let everyone know in the comments whether or not it works for you on your given platform.

This entry was posted in Operating Systems, Tips, Hacks, & Tricks and tagged , , , , , , , . Bookmark the permalink.

12 Responses to "How To Display Linux VPS Memory Usage"

Leave a reply