2

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.

https://dl.dropboxusercontent.com/u/28301519/2013-04-18_231652.png

5 Answers 5

7

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

sudo apt-get install sysstat
0
3

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.

3

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

#!/bin/bash
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.

2
  • 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, 2013 at 14:25
  • I made the edit @Oli . Thank you very much for the suggestion.
    – Raja G
    Mar 14, 2013 at 14:30
3

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

1

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'
1
  • None of these commands need sudo.
    – muru
    Feb 6, 2015 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .