How to Monitor System Resource Usage in Linux
Q: Can you explain how to check system resource usage and performance metrics in Linux?
- Linux
- Mid level question
Explore all the latest Linux interview questions and answers
ExploreMost Recent & up-to date
100% Actual interview focused
Create Linux interview for FREE!
To check system resource usage and performance metrics in Linux, you can use a variety of command-line tools that provide insights into different aspects of system performance. Here are some common methods:
1. Top Command: The `top` command is one of the most useful tools for real-time monitoring of system processes. It shows CPU usage, memory usage, and other key metrics. You can open it by simply typing `top` in the terminal. It provides an interactive interface to sort processes by different criteria such as CPU and memory usage.
2. htop Command: An improved version of `top`, `htop` provides a more user-friendly interface with color-coded output and additional features like the ability to easily send signals to processes. You might need to install it using your package manager, e.g., `sudo apt install htop`. Run it by typing `htop`.
3. free Command: To check memory usage, the `free` command is very useful. Running `free -h` provides a summary of total, used, free, shared, and cached memory in human-readable format.
4. vmstat Command: The `vmstat` command reports information about processes, memory, paging, block IO, traps, and CPU activity. You can run it by simply typing `vmstat` to get an overview of the system's performance.
5. iostat Command: For input/output statistics, you can use `iostat`. It monitors the CPU and I/O statistics from devices and partitions. You can run it using `iostat -xz 1` to get detailed statistics every second.
6. mpstat Command: The `mpstat` command provides CPU usage on a per-processor basis. This is particularly useful for multi-core systems. You can run `mpstat -P ALL 1` to see per-CPU activity every second.
7. sar Command: The `sar` command (part of the sysstat package) can be used for historical performance data. It records and reports on system activity. To check CPU usage over time, you can use `sar -u 1` to report CPU usage every second.
8. dstat Command: `dstat` allows you to view all resource usage in real-time. It’s a flexible tool that can replace vmstat, iostat, netstat, and ifstat in one go. You might need to install it, and you can run it by typing `dstat`.
9. ps Command: For a snapshot of current processes, the `ps` command shows information about active processes. You can use `ps aux` to display all processes for all users.
10. netstat and ss Commands: For network statistics, `netstat` and `ss` are commonly used. `netstat -tuln` can show active connections, while `ss -s` provides summary statistics.
These tools collectively give a comprehensive view of system performance, allowing you to diagnose issues and optimize resource usage effectively.
1. Top Command: The `top` command is one of the most useful tools for real-time monitoring of system processes. It shows CPU usage, memory usage, and other key metrics. You can open it by simply typing `top` in the terminal. It provides an interactive interface to sort processes by different criteria such as CPU and memory usage.
2. htop Command: An improved version of `top`, `htop` provides a more user-friendly interface with color-coded output and additional features like the ability to easily send signals to processes. You might need to install it using your package manager, e.g., `sudo apt install htop`. Run it by typing `htop`.
3. free Command: To check memory usage, the `free` command is very useful. Running `free -h` provides a summary of total, used, free, shared, and cached memory in human-readable format.
4. vmstat Command: The `vmstat` command reports information about processes, memory, paging, block IO, traps, and CPU activity. You can run it by simply typing `vmstat` to get an overview of the system's performance.
5. iostat Command: For input/output statistics, you can use `iostat`. It monitors the CPU and I/O statistics from devices and partitions. You can run it using `iostat -xz 1` to get detailed statistics every second.
6. mpstat Command: The `mpstat` command provides CPU usage on a per-processor basis. This is particularly useful for multi-core systems. You can run `mpstat -P ALL 1` to see per-CPU activity every second.
7. sar Command: The `sar` command (part of the sysstat package) can be used for historical performance data. It records and reports on system activity. To check CPU usage over time, you can use `sar -u 1` to report CPU usage every second.
8. dstat Command: `dstat` allows you to view all resource usage in real-time. It’s a flexible tool that can replace vmstat, iostat, netstat, and ifstat in one go. You might need to install it, and you can run it by typing `dstat`.
9. ps Command: For a snapshot of current processes, the `ps` command shows information about active processes. You can use `ps aux` to display all processes for all users.
10. netstat and ss Commands: For network statistics, `netstat` and `ss` are commonly used. `netstat -tuln` can show active connections, while `ss -s` provides summary statistics.
These tools collectively give a comprehensive view of system performance, allowing you to diagnose issues and optimize resource usage effectively.


