I have used top
to see the memory usage at the moment. But I would like to monitor the memory usage over a period of time. E.g start monitoring and then execute a few commands, and final stop the monitoring and see how much memory that have been used during the period.
How can I do this on Ubuntu Server?
I guess I could start a cronjob every 5th second or so, and invoke a command that log the current memory usage in a textfile. But what command should I use to get the current memory usage in a format that is easy to log to a text file?
I recommend combining the previous answers
Note that Linux likes to use any extra memory to cache hard drive blocks. So you don't want to look at just the free
Mem
. You want to look at thefree
column of the-/+ buffers/cache:
row. This shows how much memory is available to applications. So I just ranfree -m
and got this:I know that I'm using 1528 MB and have 2170 MB free.
Note: To stop this
watch
cycle you can just press Ctrl+C.I think
htop
is the best solution.sudo apt-get install htop
This way you will notice what programs is using most RAM. and you can easily terminate one if you want to. Here's a screenshot!
If you looking for a nice breakdown of the memory used by each running process, then I might recommend checking out ps_mem.py (found here at pixelbeat.org).
I know in the comments above, you mentioned wanting a one-line snapshot from free, but I figured others might find this useful.
Example output:
The only part I don't like is the fact that the script claims to require root privileges. I haven't had an opportunity yet to see exactly why this is the case.
Use the free command. For example, this is the ouput of
free -m
:free -m | grep /+
will return only the second line:The watch command may be useful. Try
watch -n 5 free
to monitor memory usage with updates every five seconds.You can do it using
cat /proc/meminfo
.I just found this solution and it works very well, creating a graphical interface through the CLI:
For visual monitoring of overall RAM usage, if you use Byobu, it will keep your memory usage in the lower right-hand corner of the terminal and will run while you are in any terminal session.
As you can see from screenshot, my virtual machine has a 1h3m uptime, 0.00 load, has 2.8GHz (virtual) processor and 994MB (21%) of the RAM available on the system.
Single line solution and output:
Here is an example of the expected output:
I would use Cacti. This will graph your memory usage etc over a period of time, and you will be able to check on usage using your web browser.