2

I have atop logs stored on a dayly basis with 10 min interval and I can read them with atop -r <path_to_log>, but how can I find a peak memory usage in this log?

mrgloom
  • 123
  • 1
  • 5

1 Answers1

2

The command to analyze the recorded data is atopsar.

For example:

# atopsar -r /var/log/atop/atop_20170511 -m -R 1 | head

trucka  3.4.113-sun7i+  #1 SMP PREEMPT Fri Oct 28 16:54:21 CEST 2016  armv7l  2017/05/11
-------------------------- analysis date: 2017/05/11 --------------------------
00:00:01  memtotal memfree buffers cached dirty slabmem  swptotal swpfree _mem_
00:10:01     1888M    604M    381M   422M    0M    185M     2047M   2047M
00:20:01     1888M    604M    381M   422M    0M    185M     2047M   2047M
00:30:01     1888M    604M    381M   422M    0M    185M     2047M   2047M
00:40:01     1888M    604M    381M   422M    0M    185M     2047M   2047M

You have to consider what memory is important for you in your case.

It may make sense for you to sort by the third column (memfree) to find the lowest point of free memory. You could also consider to have a look at the swapfree (9th column) to find the point where most memory is used, which causes the memory management to page out to swap.

As an example, I sort the output for lowest memory free with the sort command:

# atopsar -r /var/log/atop/atop_20170511 -m -R 1 | sort -b -k 3,3  | head

trucka  3.4.113-sun7i+  #1 SMP PREEMPT Fri Oct 28 16:54:21 CEST 2016  armv7l  2017/05/11
06:40:01     1888M    416M    400M   612M    9M    164M     2047M   2047M
06:30:01     1888M    543M    423M   483M    4M    141M     2047M   2047M
03:10:01     1888M    551M    376M   480M    0M    184M     2047M   2047M
03:20:01     1888M    551M    376M   480M    0M    184M     2047M   2047M
03:30:01     1888M    551M    376M   480M    0M    184M     2047M   2047M

Just to beautify the output, I will ignore sorting the first 7 rows of autosar's header in the following example:

# atopsar -r /var/log/atop/atop_20170511 -m -R 1 | awk 'NR<7{print $0;next}{print $0| "sort -k 3,3"}'  | head -11

trucka  3.4.113-sun7i+  #1 SMP PREEMPT Fri Oct 28 16:54:21 CEST 2016  armv7l  2017/05/11
-------------------------- analysis date: 2017/05/11 --------------------------
00:00:01  memtotal memfree buffers cached dirty slabmem  swptotal swpfree _mem_
06:40:01     1888M    416M    400M   612M    9M    164M     2047M   2047M
06:30:01     1888M    543M    423M   483M    4M    141M     2047M   2047M
03:10:01     1888M    551M    376M   480M    0M    184M     2047M   2047M
03:20:01     1888M    551M    376M   480M    0M    184M     2047M   2047M
Pablo A
  • 2,307
  • 1
  • 22
  • 34
Daniel Andersen
  • 408
  • 3
  • 8
  • What if I want just one number (minimum free memory from log)? is it possible with `awk`? – mrgloom May 12 '17 at 08:46
  • Seems it should be: `atopsar -r /var/log/atop/atop_20170512 -m -R 1 | sed 1,6d | awk '{print $3}' | sed 's:M::g' | sed 's:[^0-9]*::g'| awk 'NF' | sort -n | head -n 1` – mrgloom May 12 '17 at 10:20
  • Thats technical correct so far, but you should think about your intentions of finding out lowest "free memory". free memory can also be low, when the system uses memory as cache because the applications do not require the whole memtotal. Also paged out memory to swap *could be* important for any memory related investigations. Good luck – Daniel Andersen May 12 '17 at 10:27
  • Seems `memfree` is not 'correct', I don't know how it's calculated, but even in days without heavy load on server it shows about only 30% of memory free. – mrgloom May 12 '17 at 10:31
  • Sounds perfectly fine for me, as linux utilizes memory for buffers and caches until an application requires more memory. try out: `free -m` and compare "free memory" with "available memory": `daniel@trucka:~$ free -m` `total used free shared buff/cache available` `Mem: 1888 312 734 17 840 1496` `Swap: 2047 0 2047` As you can see in my example: there is 1496M of memory available, but 840 are currently used for caches (which is fine). – Daniel Andersen May 12 '17 at 10:41
  • And how to obtain memory which fro example `htop` shows in 'Mem' bar? – mrgloom May 12 '17 at 10:42
  • `htop` is using: `Mem:1.84G used:331M buffers:341M cache:483M` `autosar` shows you the same values at: `memtotal, buffers, cached`. "used" memory in htop can be calculated out of the autosar export with: memtotal - memfree - buffers - cached = usedmemory – Daniel Andersen May 12 '17 at 10:45
  • @DanielAndersen,how to read several days log and `head`? – kittygirl Mar 14 '19 at 08:34