Memory checks on LINUX part 1

How to

1. at first basic check by one command

In output we can see utilization of memory and and swap. we can change output with -b bytes -k kilobytes instead of -m megabytes. Option -t is used for showing memory with swap (-t as total).

# free -tm
             total       used       free     shared    buffers     cached
Mem:        128393      82606      45787          0       9873      40943
-/+ buffers/cache:      31789      96604
Swap:        34815       4773      30042
Total:      163209      87379      75830
#

If we are not satisfied with this output we can be more detailed by next scripts.

2. How to check utilization of physical memory

This short script we can use to see how much is memory used.

# echo;echo "Mem statistics:";echo;\
> TOTAL=`free|grep -i mem|awk '{print $2}'`;USED=`free|grep -i mem|awk '{print $3}'`;\
> echo -e "Total mem:   "$TOTAL;\
> echo -e "Used mem:    "$USED;\
> PERCENTAGE=`expr \($USED/$TOTAL\)*100 |bc -l`;\
> echo -e "%_USED:       "$PERCENTAGE;\
> echo;

Mem statistics:

Total mem:   131475404
Used mem:    84584780
%_USED:       64.33505996300266169900

#

3. How to check swap used on system

The same we can use for swap.

# echo;echo "Swap statistics:";echo;\
> TOTAL=`free|grep -i swap|awk '{print $2}'`;USED=`free|grep -i swap|awk '{print $3}'`;\
> echo -e "Total swap:   "$TOTAL;\
> echo -e "Used swap:    "$USED;\
> PERCENTAGE=`expr \($USED/$TOTAL\)*100 |bc -l`;\
> echo -e "%_USED:       "$PERCENTAGE;\
> echo;

Swap statistics:

Total swap:   35651576
Used swap:    4887560
%_USED:       13.70923967007797916100

#

As we can see system in this example has memory used by 64% and swap by 13%. In part 2 I will show you how to check which processes consuming most of memory.

Leave a Reply