0

I need a program or tool to record the memory usage ( RAM ) and save it to a file so i can take the file and open it. so i can see the result and make the comparison with other by myself.

1
  • 1
    You get the RAM usage with the command free. If you want to log the RAM usage, you can make a script that redirects the output of free to a file at regular intervals, for example every 5 seconds (maybe together the the current time).
    – sudodus
    Jan 2, 2017 at 7:22

2 Answers 2

6

You can use the following command in bash like so:

for i in `seq 0 60`; do
  echo `cat /proc/meminfo | grep Active: | sed 's/Active: //g'` >> usage.txt
  sleep 1m
done

This command will record the current memory use to a file named 'usage.txt' every minute for the duration of 1 hour.

If you wish, you can change the usage.txt part of the command to save under a different name. You can also change the sleep 1m command to alter the time between each entry and the '60' in the seq section at the top to change the number of entries to be recorded.

When you have finished making your entries, you will have a text file of entries that can be imported into a spreadsheet for easy comparison.

EDIT: If you wish to also record the total memory with each entry, you can use the following commands:

for i in `seq 0 60`; do
  echo `cat /proc/meminfo | grep Active: | sed 's/Active: //g'`/`cat /proc/meminfo | grep MemTotal: | sed 's/MemTotal: //g'` >> usage.txt
  sleep 1m
done

These commands will instead record entries in the form of <active>/<total>

3
  • thanks a lot your answer is very useful and simple and i still want to record the total memory too so i will appreciate if you can rewrite the code above to make it record the MemTotal and Active at the same time
    – Basheer
    Jan 3, 2017 at 6:22
  • I will assume that you want it to record one entry per line in the form <active>/<total>
    – Jake
    Jan 3, 2017 at 9:57
  • This was useful for me too. In my case, I needed continual monitoring for a long-running application, so I just put this into an infinite loop (while true; do ...), then when the application finishes, I just kill the process.
    – rayryeng
    Jun 3, 2022 at 13:17
1

sysstat does exactly that -- runs on a cron schedule and records various system metrics (CPU, RAM, block device usage and so on). Basically you apt-get install sysstat and forget about it. By default it keeps the metrics for the last month.

Later when need to disgnose an issue, you can use its CLI, sar, to browser the data or an 3rd party GUI, ksar for visualisation.

You must log in to answer this question.

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