Reader small image

You're reading from  Mastering Ubuntu Server - Fourth Edition

Product typeBook
Published inSep 2022
PublisherPackt
ISBN-139781803234243
Edition4th Edition
Concepts
Right arrow
Author (1)
Jay LaCroix
Jay LaCroix
author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix

Right arrow

Monitoring System Resources

In the last chapter, we learned how we can manage tasks that are running on our server. We now know how to see what’s running in the background, how to enable or disable a unit from starting at boot time, and also how to schedule tasks to run in the future. But in order for us to be able to effectively manage the tasks that our servers carry out, we also need to keep an eye on system resources. If we run out of RAM, fill up our disk, or overload our CPU, then a server that normally processes tasks very efficiently might come to a screeching halt. In this chapter, we’ll take a look at these resources and how to monitor them.

Our discussion on resource management will include:

  • Viewing disk usage
  • Monitoring memory usage
  • Understanding load average
  • Viewing resource usage with htop

One resource that is extremely important on our servers is storage, and keeping track of such things as available disk space...

Viewing disk usage

Keeping an eye on your storage is always important, as no one enjoys getting a call in the middle of the night saying that a server encountered an issue, especially not something that could’ve been easily avoided, such as a filesystem growing too close to being full. Managing storage on Linux systems is simple once you master the related tools, the most useful of which I’ll go over in this section. In particular, we’ll look at tools we can use to answer the question “what’s using up all the disk space?”, which is the most common question that comes up when dealing with disk usage.

First, let’s look at the df command.

Using df

The df command is likely always going to be your starting point in situations where you don’t already know which volume or mount point is becoming full. When executed, it gives you a high-level overview, so it’s not necessarily useful when you want to figure out who...

Monitoring memory usage

I forget things all the time. I regularly forget where my car keys are, even though they’re almost always right there in my pocket the entire time. I even forget to use sudo for commands that normally require it, despite working with Linux for over 20 years. Thankfully, computers have a better memory than I do, but if we don’t manage it effectively, the memory on our servers will be just as useless as I am when I forget to put freshly washed laundry in the dryer.

Understanding how Linux manages memory can actually be a somewhat complex topic, as understanding how much memory is truly free can be a hurdle for newcomers to overcome. You’ll soon see that how Linux manages memory on your server is actually fairly straightforward once explained.

Understanding server memory

For the purpose of monitoring memory usage on our server, we have the free command at our disposal, which we can use to see how much memory is being consumed at...

Understanding load average

Another very important topic to understand when monitoring performance is load average, which is a series of numbers that represents your server’s trend in CPU utilization over a given time. You’ve probably already seen these series of numbers before, as there are several places in which the load average appears. If you run the htop utility, for example, the load average is shown on the screen. In addition, if you execute the uptime command, you can see the load average in the output of that command as well. You can also view your load average by viewing the text file that stores it in the first place:

cat /proc/loadavg

Personally, I habitually use the uptime command in order to view the load average. The primary purpose of the uptime command is to display the amount of time that the server has been in use, and this time resets anytime you power off or reboot the server. But in addition to how long the server has been powered on, the...

Viewing resource usage with htop

When wanting to view the overall performance of your server, nothing beats htop. Although not typically installed by default, htop is one of those utilities that I recommend everyone installs as soon as possible, since it’s indispensable when wanting to check on the resource utilization of your server. It’s so useful in fact that I’ve mentioned it several times earlier in this chapter, even before we started an actual discussion about it in this section. It’s a great utility.

If you don’t already have htop installed, all you need to do is install it with apt:

sudo apt install htop 

When you run htop at your shell prompt, you will see the htop application in all its glory. In some cases, it may be beneficial to run htop as root, since doing so does give you additional options such as being able to kill processes, though this is not required:

Figure 8.7: Running htop

At the top of the htop...

Summary

In this chapter, we learned how to monitor our server’s resource usage. We began with a look at the commands we can use to investigate disk usage, and we learned how to monitor memory usage as well. We also discussed swap, including what it is, why you’d want to have it, as well as how to create a swap file manually should the need to do so come up. We then took a look at load average and closed out the chapter by checking out htop, which is my favorite utility for getting an overall look at resource usage on servers.

In Chapter 9, Managing Storage Volumes, we’ll take a closer look at storage. In this chapter, we learned how to see how much is being used, but in the next, we’ll look at more advanced concepts surrounding storage, such as formatting volumes, adding additional volumes, and even LVM. See you there!

Relevant videos

Further reading

Join our community on Discord

Join our community’s Discord space for discussions with the author and other readers:

https://packt.link/LWaZ0

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Ubuntu Server - Fourth Edition
Published in: Sep 2022Publisher: PacktISBN-13: 9781803234243
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix