How to Use Sar (System Activity Reporter)

Overview

In this article, we’re going to take a look at the System Activity Reporter, also known as the sar command. This command will help us with seeing a historical view of the performance of our server. You’ll see examples of installing it, running it manually, and more. Let’s get started!

Prerequisites

Before we do get started, there’s a few quick things to mention. If your server is a production server, then I hope you’ve already installed all available updates. There’s already articles within Linode’s documentation when it comes to updating packages.

To get started, we’ll first need to install the sar command, which is available in the sysstat package:

sudo apt update
sudo apt install sysstat

Installation of the sysstat package should be fairly fast.

However, having the sysstat package installed by itself isn’t enough – we’ll need to configure its defaults. We can use the nano text editor, for example, to edit the /etc/default/sysstat file:

sudo nano /etc/default/sysstat

The first change to make within this file, is to enable stat collection:

ENABLED="true"

Save the file, and then we’re all set with that file in particular.

Optionally, you could consider editing other configuration files that configure sar:

  • /etc/cron.d/sysstat

  • /etc/sysstat/sysstat

The first configures how often stats are collected, the second example will give you even more options to fine-tun sar, which might be useful. Feel free to take a look at it.

The data file

List the storage of the /var/log/sysstat/ directory:

ls -l /var/log/sysstat/

sar will run every ten minutes by default, so if ten minutes hasn’t passed since you’ve enabled stat collecting, then wait a bit, and it should be present.

Running the sar command

Here’s an example of sar in action:

sudo sar -u -f /var/log/sysstat/saNUM

Note: NUM in the example is a placeholder for the number next to your data file, which will actually be the same as the date, specifically the day of the month (for example, sa22 corresponds to the 22nd of the current month). The output will give you the overall performance for your server at a given time.

Continuing, let’s look at a simpler example:

sar -u

This should give you the same output as before, but without waiting for the data file to be updated.

Yet enother example to show you, is the

sar -r

The output of sar -r gives you info pertaining to memory usage. We also have a dedicated option for swap usage:

sar -S

If you run into an issue where your server is slow (but you aren’t sure why) run the following:

sar -b

The -boption gives you info regarding input/output, which can be a typical culprit if you’re experiencing slowdown.

Closing

Of course, there’s other ways to use the sar command, so be sure to check out other articles and videos that Linode has available.

You can watch the tutorial here:

[embedded content]