Command To Check Memory Usage In Linux.

Here is the list of commands that can be used to check memory usage in Linux. 

1) grep 

You can use the grep command to search all log files in /var/log/ location for an out-of-memory error.

grep -i -r 'out of memory' /var/log/

2) free -m

You can use the command “free” to find the current memory usage in the server.

free -m

The command will show you the current RAM and swap usage in MB.

3) sar

The history of memory usage for the day can be found using the “sar” command.

sar r

4) top -c

Another tool to identify the Memory consuming processes is the “top” command, which will give you the option to sort the running processes based on their resource usage.

For a cPanel server, you can use the grep command to search the website access logs to see any suspicious/abusive access to the website to cause this resource exhaustion.

Example: grep -ir “05/Jul/2022:10:20” /usr/local/apache/domlogs/

Some suspicious activities identifiable from the access logs are

High access from specific IP addresses.

High access to unavailable resources/files etc.

High number of HTTP POST requests.

High number of failed access attempts like login.

Use the command mysqladmin proc stat to identify any MySQL queries hanging for a long time to cause a high memory usage for them.

mysqladmin proc stat

Was this answer helpful?

« Back