Skip to content

How to Check Memory Usage on CentOS

  • by

Monitoring memory usage on your CentOS server is crucial for ensuring its optimal performance and stability. Understanding how to check memory usage allows you to identify potential issues and take necessary actions. In this detailed guide, we will explore various methods and commands to help you check memory usage on your CentOS system.

Using the free Command

The free command provides a straightforward way to check the system’s memory usage. Open your terminal and enter the following command:

free -m

This command will display memory-related information in megabytes (MB) for your system:

  • Total: The total amount of physical RAM on your system.
  • Used: The amount of RAM currently in use.
  • Free: The amount of unused RAM.
  • Shared: Memory used by shared libraries.
  • Buffers: Memory used by the buffer cache.
  • Cached: Memory used for the page cache.

You can also use the -h option to display memory values in a more human-readable format:

free -h

Checking Memory Usage with top

The top command is a powerful interactive system monitoring tool that provides real-time information about system resource usage. To check memory usage, open the terminal and run:

top

You will see a list of running processes and memory statistics at the top of the output. Look for the “KiB Mem” line, which shows the total, used, free, and cached memory. To exit top, press Ctrl+C.

Using the vmstat Command

The vmstat command reports virtual memory statistics, including memory usage. To check memory usage with vmstat, open the terminal and run:

vmstat

The vmstat output provides information about processes, memory, and system activity. Look at the columns under the “swpd,” “free,” “buff,” and “cache” headings for memory-related information.

Analyzing Memory Usage with htop

htop is an interactive process viewer that provides detailed information about system resource usage, including memory. To check memory usage with htop, you need to install it first:

sudo yum install htop

After installation, you can run htop:

htop

htop displays memory usage information in the top part of the window. It includes details about total, used, free, and shared memory.

Using the cat /proc/meminfo Command

The /proc/meminfo file contains detailed information about your system’s memory usage. You can view its contents with the cat command:

cat /proc/meminfo

The output includes various memory-related metrics, such as the total memory, free memory, and memory used by the system cache.

Checking Memory Usage with nmon

The nmon tool provides a comprehensive overview of system performance, including memory usage. To use nmon, you need to install it:

sudo yum install nmon

After installation, you can run nmon:

nmon

In the nmon interface, you can access memory statistics by pressing the “m” key. It provides a detailed breakdown of memory usage, including physical memory, virtual memory, and swap space.

Using sar (System Activity Reporter)

The sar command is a part of the sysstat package and allows you to collect, report, and save system activity information, including memory usage. First, install the sysstat package:

sudo yum install sysstat

Then, you can use sar to check memory usage:

sar -r

This command displays memory statistics, including the average memory usage over time.

Conclusion

Monitoring memory usage on CentOS is crucial for maintaining system performance and stability. Each of the methods described in this guide provides valuable insights into how memory is being used on your system. Whether you prefer a real-time interactive tool like top or a detailed breakdown from the /proc/meminfo file, CentOS offers various ways to check memory usage, allowing you to proactively manage your system’s resources and respond to potential issues as needed.

Visited 1 times, 1 visit(s) today

Leave a Reply

Your email address will not be published. Required fields are marked *