glances fi

How to Monitor Your Server’s Resource Consumption on Linux

Linux server monitoring is always one of the most enjoyable yet challenging activities as a system administrator. Monitoring your Linux server’s resource consumption entails mastery of the fundamental aspects of the Linux system.

The importance of monitoring your system’s resources cannot be underestimated, as this gives you a bird’s eye view of the server’s health—as well as alert you in case of potential system downtime or threats in your system.

In this guide, we will be exploring the different resources a server uses, such as CPU, memory, disk space and other relevant matter. We will employ both native and readily available open-source tools on your trusted repositories.

How to Monitor your CPU and Memory consumption 

CPU and memory allocation go hand in hand in any server configuration. Most, if not all monitoring tools have already integrated CPU and memory consumption into their outputs. We will be examining natively installed tools and tools you can install.

Monitoring using Top command

The top command has always been a reliable tool readily available in your system. It provides a dynamic real-time view of a running system. And it can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.  

In general, top provides a system summary of information such as system uptime, PID, and memory allocation, among others. The types, order, and size of information displayed for processes are all user configurable and that configuration can be made persistent across restarts.

To display system process using the top, invoke the command:

$ top

Output:

top monitoring

To exit the top display output, simply press the “Esc” key.

If you’re curious for an in-depth discussion on using the top utility, you can check this link for more tips and tricks.

Monitoring using Htop command

Htop is a free ncurses-based process viewer for Linux. It is similar to top it but allows you to scroll vertically and horizontally. So with it, you can see all the processes running on the system, along with their full command lines.

Tasks related to processes (killing, renicing) can be done without entering their PIDs. Additionally, Htop also offers more functionalities than top, with improvements on certain aspects and display. You can check out more Htop commands by clicking the provided link.

Htop is not natively available on your linux system, so to install it, execute the following commands.

For Debian-based OS:

$ sudo apt install htop

For Fedora-based OS:

$ sudo dnf install htop

To display and run the htop command, execute:

$ htop

Output:

htop process monitoring

Htop, in a gist, is more user-friendly as it displays key shortcuts you can use at the bottom of the Terminal.

You can press the “F10” or “Q” key to quit.

Monitoring using Glances command

Another helpful tool to monitor your CPU and Memory consumption is Glances. It’s a free curses-based monitoring tool that aims to present a maximum of information in a minimum of space. This tool is ideally to fit in a classical 80×24 terminal. 

Glances can dynamically adapt the displayed information depending on the terminal size. It is also written in Python and uses PsUtil to fetch the statistical values from key elements.

Like Htop, glances is also not natively available on your Linux system, so to install it, execute the following commands.

For Debian-based OS:

$ sudo apt install glances

For Fedora-based OS:

$ sudo dnf install glances

To display and run the glances command, execute:

$ glances

Output:

glances server monitoring

Glances offers many more functionalities, such as network throughput, and disk writes and reads. You can also monitor clients remotely, plus other cool stuff and easy-to-read indicators.

To exit the top display output, simply press the “Esc” key.

How to Monitor your Disk performance and consumption

Disk performance and consumption is an equally important resources that must be checked and monitored continuously. By default, Linux provides native tools we can use to check your disk space and performance.

Df Command

The simplest way to tell how much disk space you are currently consuming through the terminal is the “df” command. Df provides a summary of your disk consumption on all mounted partitions, local or over the network. 

If an argument is the absolute file name of a disk device node containing  a mounted file system, df shows the space available on that file system rather than on the file system containing the device node.

To demonstrate, issue the command:

$ df -hT

Output:

df command

Iostat Command

Next on our list is the iostat command. It’s used for monitoring system input/output device loading by observing the time the devices are active regarding their average transfer rates. 

The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks.

Iostat is not natively available on your Linux system, so to install it, execute the following commands.

For Debian-based OS:

$ sudo apt install sysstat

For Fedora-based OS:

$ sudo dnf install sysstat

To display and run the iostat command, execute:

$ iostat -h

Output:

iostat disk monitoring

Iostat only prints the disk performance on any given time, so it does not become interactive. However, you can add a ‘-d [interval]’ to print the output at an interval convenient for your purpose.

Iotop Command

Iotop is another utility tool you can use to interactively monitor your device’s disk performance and consumption in real-time. It displays columns for the I/O bandwidth read and written by each process/thread during the sampling period. 

Iotop also displays the percentage of time the thread/process spent while swapping in and waiting on I/O. For each process, its I/O priority (class/level) is shown. In addition, the total I/O bandwidth read and written during the sampling period is displayed at the top of the interface.

Like iostat, iotop is also not natively available on your Linux system, so to install it, execute the following commands.

For Debian-based OS:

$ sudo apt install iotop

For Fedora-based OS:

$ sudo dnf install iotop

Iotop needs to be invoked with root privileges, so to display and run the iostat command, execute:

$ sudo iostat

Output:

iostat linux server disk

How to Monitor your Network bandwidth

Monitoring your network performance and bandwidth should be something that also needs to be considered and thoroughly discussed. There could be several performance problems being experienced by your applications mainly because of network bottlenecks.

Iftop Command

Iftop monitors your network bandwidth by counting all IP packets that pass through the filter. Plus, the direction of the packet is determined according to the direction the packet is moving across the interface. 

It listens to network traffic on a named interface, or on the first interface it can find, which looks like an external interface if none is specified. Additionally, it displays a table of current bandwidth usage by pairs of hosts. 

Iftop must be run with sufficient permissions to monitor all network traffic on the interface.

If the Iftop command is not natively available on your Linux system, so to install it, execute the following commands.

For Debian-based OS:

$ sudo apt install iftop

For Fedora-based OS:

$ sudo dnf install iftop

To display and run the iftop command, execute:

$ sudo iftop

Output:

iftop server

Iptraf Command

Iptraf is another ncurses-based IP LAN monitor that generates various network statistics—which includes TCP info, UDP counts, ICMP and OSPF information, Ethernet load info, node stats, IP checksum errors, and others.

If the command is issued without any command-line options, the program comes up in interactive mode, with the various facilities accessed through the main menu.

Like Iftopt, iptraf is not natively available on your Linux system, so to install it, execute the following commands.

For Debian-based OS:

$ sudo apt install iptraf

For Fedora-based OS:

$ sudo dnf install iptraf

To display and run the iptraf command, execute:

$ sudo iptraf

Output:

iptraf server

Other Advanced Monitoring systems available

There are also a ton of other monitoring tools available both as open-source and as proprietary. Some of the well-known monitoring systems are Zabbix, Nagios, and Cacti. 

Final thoughts

There are countless ways you can monitor and keep track of your Linux system’s resources. Some of the examples given are just a few of the popular tools used by systems and network administrators.

If this guide helped you, please share it. ?

Leave a Reply
Related Posts