I checked few programs such as htop or top command but couldn't find any features for logging per minute.

Is there a way to do that for tracking memory issues ?

edit: I was using linode and decided to use Longview.



Install and configure the sysstat package, which does just what you're asking for.

sudo apt-get install sysstat

If I were doing this I'd probably script something up with RRDtool.

RRDtool is something that is built for interval-based data-collection and then building graphs off the back of the data. If you've ever seen a netgraph on an ISPs control panel, it was probably done with RRDtool.

How you implement it is up to you. There are "pure" bash solutions with cron but there are also nice Python and Perl options floating around out there too:

If you want a lot more than this, check out Munin. This uses RRDtool prolifically to log a whole load of system data and generates static HTML pages at a set interval.


There is one more way to do this. By using cron jobs we can get this.

* * * * * username /path/to/./script.sh

the script is simply

echo "$(date +%Y%m%d-%H%M%S) $(free -mt | awk 'END{print $4}')" >> ~/memlog.txt

before placing the script do

chmod +x script.sh

so create above script and do it as I said then place the script at /usr/bin location . then open your /etc/crontab with

sudo nano /etc/crontab

and place the first line there . That script executes for every minute and gives memory details for every minute .

So finally that log.txt file will hold the Memory log details for every minute.

and I have got one more useful information for you that

watch cat log.txt will show the log.txt file in terminal and it will update the content live.so in the current terminal it self with one time typing you can have live watch of the log.txt file.

  • 1
    Writing the date/time on the same might be a good idea so there's a reference point. Something like this: echo "$(date +%Y%m%d-%H%M%S) $(free -mt | awk 'END{print $4}')" >> ~/memlog.txt – Oli Mar 14 '13 at 14:25
  • I made the edit @Oli . Thank you very much for the suggestion. – rɑːdʒɑ Mar 14 '13 at 14:30

vmstat -S M 60 would do (in megabytes).

You only have to remember that actually free RAM is "free + cache + buf".

For logging purpose it might have sense to print it out time stamped which can be accomplished in various ways, for e. g.:

vmstat -nS M 60 | while read _vmstat; do echo $(date --rfc-3339=seconds) $_vmstat; done


Here my trick. With this command I append reports of free, vmstat and top into txt files every 5s.

 watch -n 5 'free -mt  >> free-report.txt && vmstat -S M >> vm-report.txt && top -b -n1 >> top-report.txt'
  • None of these commands need sudo. – muru Feb 6 '15 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.