Monitoring Resource Usage in Ubuntu with top

Posted by on October 27, 2011 in Operating Systems, Ubuntu | 0 comments

When you want to monitor the resources that are being used by your processes, the top command comes in handy. You can see a breakdown of the CPU usage by process, and memory usage as well. There are a few things I use top for regularly.

  • To monitor whether the CPU usage is too high.
  • To monitor whether Memory usage is too high.  — This can be misleading sometimes because of cache issues.
  • To monitor whether the machine has entered into SWAP yet.   I hate when a machine swaps, so I want to be alerted when it has entered into the swap state because I have never seen a machine get out of swap on its own.
  • To monitor if certain cores of the CPU are not being used.
  • To see if a process is a runaway and not finishing.
There are some useful commands and arguments for top:
  • -d Tells top how often to refresh.  If you’re looking for a spike in MySQL for instance, you may need to set this to a lower value than the default 3 seconds.
  • -n  Tells top how many times to refresh before stopping.  Useful if you’re using an automated script that’s looking for a snapshot.
  • -b Lists out all the processes in a single dump.  Also useful if you’re parsing the results with a script.
  • Pressing 1 while in top.  Shows you the usage of each CPU core, and not just the summary of the whole.
Below are examples of the commands shown above.
top -d 1
top -n 1
top -b -n 1
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>