
Monitoring Linux Server resources is an important aspect of system administration that lets you track the general server performance and ensure system reliability. To monitor server resources, you can use built-in system utility tools, or install secondary tools to view real-time resource usage and performance statistics.
Linux Server CPU, GPU, memory, and storage devices are some of the major system resources that require constant monitoring. If any important resource fails or performs beyond the allowed capacity, it can directly affect the server performance and lead to system application failures.
This article explains how to monitor Linux Server resource usage and display performance statistics using utility tools to keep track of the general system performance.
Before you begin:
NVIDIA Management Interface (nvidia-smi) is a cross-platform command line utility that monitors attached GPU devices, VRAM usage,and performance statistics on a GPU-powered Linux Server. By default, nvidia-smi is available as part of the NVIDIA GPU drivers package. You can use the tool to display GPU information in XML or plain test formats.
Run the nvidia-smi command to monitor your server GPU usage
To periodically update nvidia-smi to view real-time performance and usage information, use the watch utility. For example, run the following command to refresh the nvidia-smi output every 5 seconds.
Press Ctrl + C to stop the watch process.
For more information about the nvidia-smi utility, visit the official documentation.
Disk Free (DF) is a built-in Linux utility that allows you to monitor the server disk space usage and attached storage device data directories. Using the tool, you can monitor the available file system directories, used space, free space, and mounting locations for each storage device attached to your server.
Run the df command to view your server disk usage information.
Your output should look like the one below:
df displays disk usage in Kilobits. To view data in a human-readable form of Kilobytes, Megabytes, and Gigabytes, use the -h option.
Output:
To view information about a specific device volume, specify the filesystem path. For example, view the main system volume /dev/vda2 with the filesystem type T and human readable h options.
Output:
The df command output includes the following sections:
/dev/vda2 virtual disk ID while the boot volume uses /dev/vda1. Additional volumes such as /dev/vda3, /dev/vda4 may represent secondary partitions or volumes such as Vultr Block Storage./ represents the root Linux server directory where all system files are stored. Files written to a mount directory are added to the storage volume.For more information and storage monitoring options, view the df manual page.
free is a built-in utility that displays information about the server memory usage. It's part of the default procps utilities package and allows you to view available and used memory on the server. This includes the default system memory (RAM) and SWAP memory borrowed from the disk. Run the free command together with your desired memory measurement value to view the active usage statistics.
By default, the free command without any option displays memory usage in Kibibytes.
Your output should look like the one below:
To modify your memory measurement value, use any of the following options:
-b: Bytes-k: Kibibytes-m: Mebibytes-g: Gibibytes--kilo: Kilobytes--mega: Megabytes--giga: GigabytesTo generate a more readable output, apply the human-readable option -h to display the server memory usage in Megabytes.
Output:
Below are the command sections:
To monitor the server memory usage in real-time, use the watch command to continuously update the usage statistics. For example, run the following command to update the memory usage statistics every after 3 seconds.
To view detailed information about swap memory. Use the swapon command.
Your output should look like the one below:
For more information, and free utility memory usage options, view the command manual page.
Top is a built-in command-line utility that displays real-time information about the server resources and processes. It offers a dynamic interface that includes the system information, CPU usage, memory usage, and actively running server processes or threads. Within the top interface, you can monitor and kill any server processes to optimize the system performance.
By default, top is available in the default procps-ng system package. In case of any errors or unavailability, install the package using the default system package manager.
Debian/Ubuntu:
CentOS/Rocky Linux/ RHEL-based systems
To use the tool, run the top command.
Your output should look like the one below:
The top interface is divided into the following sections:
Press Q to exit the top interface.
To limit the top output to strictly display processes started by a user, apply the -u option together with the target username. For example, linuxuser.
Output:
To kill an active process on the server, press k, enter the Process ID to stop, and press Enter to end the process thread.
For more information and command options, view the top command manual page.
Virtual Memory Statistics (VmStat) is a built-in utility that displays real-time information about the system memory, virtual memory, paging, and CPU activity. It's an important tool that allows you to constantly monitor your Linux server performance, identify memory-related issues, and analyze how running processes utilize the available system resources.
By default VmStat is part of the Linux procps-ng package, to use the tool, run the vmstat command.
Output:
Below is what the vmstat information categories represent:
To update the VmStat output after a specific time, include the time range as a command option. For example, update the output after every 2 seconds.
To display a specific number of monitoring reports, include the count interval value as an option. For example, to update the monitoring information every 2 seconds and generate only 10 reports, run the following command.
To view a summary of the server memory and CPU usage statistics, use the -s option.
Output:
To view server disk statistics, use the -d option.
Output:
To further optimize your VmStat monitoring output, view the command manual page and use any of the following options.
The available options include:
-a: Views the active server memory statistics and displays active and inactive memory pages.-m: Displays information about the server Kernel slab cache memory usage.-n: Shows column headers only once instead of every update interval.-s: Displays a summary of memory usage, CPU and I/O statistics.-d: Displays disk I/O statistics including read and write operations to storage devices.-S: Sets the memory size display units. For example, vmstat -S M displays the memory values in Megabytes.-t: Includes a timestamp on each output line.Process Status (PS) is a built-in command line utility that displays information about actively running processes on your Linux server. Using the tool, you can view processes started by all users, a specific Linux user, or system daemons. In addition, you can filter the listed information using the grep utility to search for specific processes on the server.
Run the ps command to view actively running processes in your terminal session.
Output:
To view all actively running processes on the server across all terminal sessions, use the aux option.
Output:
To sort the system processes information, use the --sort= option and include your target value. For example, sort the server processes by memory usage.
Other sorting values include:
-%cpu: Sorts running processes by the CPU usage percentage in descending order. Applying + instead of - sorts the usage values in ascending values.-%mem: Displays running processes based on the memory usage percentage in descending order.+rss: Displays processes based on the real-time memory usage.+start_time: Displays processes based on the start time in ascending order. Old processes first are display first and newer processes last.+user: Sorts the running processes based on the user and process owner values.To view the processes started by a specific user, apply the -u option and the target username.
To view the command in full format with additional values such as User ID, process ID, and CPU utilization details, use the -f option.
To view more ps process monitoring options, view the command manual.
Htop is an interactive system process viewer that displays real-time information about active server processes, CPU, and memory usage. It's an improved version of the built-in top utility with additional monitoring features and capabilities. To use Htop on your server, install the latest version using the default system package manager.
Install Htop:
Debian/Ubuntu:
CentOS/Rocky Linux/Fedora/RHEL systems
Verify the installed Htop version.
Output:
Open the Htop interface to view active server processes.
Within the Htop interface, monitor the Process section to view real-time statistics of all actively running server processes. To navigate through the additional features, use a combination of keyboard function key shortcuts and interactive commands listed at the bottom of the interface.
Press :key_q: to stop monitoring and close the Htop interface.
To modify the Htop interface, define an option while starting the command. For example, display processes with a hierarchical tree view.
For example:
-t: Displays system processes in a tree view depending on the parent directory to monitor process hierarchies.-C: Start Htop in monochrome mode without any coloring.-d: Sets the processes update interval in seconds. For example, -d 5 updates the process information every 5 seconds.-p: Displays information about specific process IDs (PIDs). You can specify one or more PIDs as arguments using this option. For example, -p 623 displays statistics for the process ID 623.-u: Displays processes owned by a specific user on the Linux server. For example, -u example-user displays all active processes started by example-user.-H: Hides threads and displays only the parent process for multi-threaded applications.For more information and monitoring options, view the Htop manual page.
List Open Files (LSof) is a built-in tool that displays information about all open files and directories in use by system processes. This allows you to keep track of open directories and server processes that actively use specific files on the server. To use lsof, start the command with sudo privileges to view all processes or monitor specific processes using the respective process ID.
List all open files in use by active processes and the respective process IDs on your server.
Your output should look like the one below:
List open files in use by server processes on a specific directory. For example, view open files in use by system processes on the root system directory /.
List all files in use by processes started by a specific user.
Output:
List all server processes that use a specific network port. For example, view all processes using the HTTP port 80.
List files in use by a specific program or server application. For example, view all files in use by the Apache web server
To display accurate information, use the main application executable binary file. When successful, your output should look like the one below:
To find the binary location of a specific application on your server, use the which command to view the active path.
For more information and command options, view the lsof manual page.
iotop is a real-time interactive Input/Output (I/O) process monitoring tool that allows you to view processes or threads actively accessing the server storage devices. It allows you to identify processes that consume the most disk I/O bandwidth and provides insights into how different processes interact with storage devices. Within the output, the read-write speed, time spent on swapping, priority class, command, and the respective process users make it possible to actively track events on the server. To use iotop, install the version using your default system package manager.
Install iotop:
On a Debian or Ubuntu server:
CentOS/Rock Linux or Fedora Linux
Verify the installed iotop version
Output:
Open the iotop interface to start monitoring all server processes
Output:
Within the interface, identify resource-intensive server processes, troubleshoot I/O performance issues, and optimize the server storage usage based on the active processes.
Press Q on your keyboard to close the iotop interface.
To view active server processes performing I/O operations instead of all system threads, use the -o option.
To include a timestamp on all server processes, apply the -t option.
To view server processes started by a specific system user, apply the -u option. For example, view processes started by linuxuser.
Output:
To further modify your iotop output, implement more options such as:
-n: Sets the number of iterations in batch mode before iotop exits. For example, -n 5 runs only 5 iterations and stops.-a: Shows the number if I/O processes instead of bandwidth.-b: Starts iotop in batch mode with a continuous output necessary for logging or scripting operations.-d: Sets the iotop update interval in seconds. For example, -d 2 updates the output every 2 seconds.-p: Displays I/O information for a specific process ID. For example -p 1121 displays I/O processes started by the Process ID 1121.-q: Removes the output header and summary information to display only active processes.For more information and command options, view the iotop manual page.
Uptime is a basic Linux utility that monitors the server uptime, actively logged-in users, and system load averages. Using the tool, you can keep track of the server boot time, CPU idle time, and the uptime duration since the last reboot. To use the tool, verify the installed version on your system, then, apply fine-tune your output using the available command options.
Verify your system's Uptime utility version.
Output:
View the Server Uptime, logged-in users, and the system load averages.
Output:
View the Server Uptime in hours and minutes.
Output:
View the last server reboot date.
Output:
strace is a Linux diagnostic utility tool that monitors system calls and signals. It runs a specific program or command until it exits to keep track of the system calls made by the process, and the signals received by the process. This allows you to monitor the performance of Kernel state functions while executing a specific command for debugging, and troubleshooting purposes.
Install strace if it's not available on your server:
Debian/Ubuntu:
CentOS/RHEL systems:
Verify the available strace version on your server
Output:
Using strace, trace the calls of a specific server application. For example: apache2
Your output should look like the one below:
To monitor a specific process on the server, use the -p option and include the process ID. For example, trace the process ID 1121.
For more information, view the strace command manual page.
You have applied Linux resource monitoring tools to keep track of the server CPU usage, memory usage, system processes, and Kernel messages. To fine-tune your server performance, you should continuously track each tool's output to manage high-resource processes or upgrade necessary resources to meet the server demands. For more information about each tool, view the command manual page to explore the additional usage options.
0 Comments
Be the first to comment and share your perspective with the community.