Monitoring your server resources is a crucial part of identifying any bottlenecks and possible issues on your server.
The sar
command allows you to capture the utilization of your resources like RAM, CPU, Disk I/O and etc.
In this post, I will show you how to install and configure sar
!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Prerequisites
In order to complete this tutorial, you will need to have an Ubuntu 18.04 server with a non-root sudo-enabled user account and a basic firewall. This can be configured using our initial server setup guide for Ubuntu 18.04.
Installing sar/sysstat
First, let’s start by updating your local repositories:
After that as the
sar
command is part of thesysstat
package in order to install it, you need to run the following command:After that you can check the
sar
version by running the following:Configuring sar/sysstat
After the installation, make sure to start and enable the
sysstat
service:This will add the required cron jobs so that the system data is collected accordingly.
The cron jobs will be added at:
And the file will look like this:
Using of sar
In order to
The
sar
command has a lot of arguments and options, but here is a list of some of the most popular ones which you might need:Let’s start by checking the CPU usage on your server:
This will show you the CPU usage for the current day.
If you wanted to check the current usage in real-time, you could specify 2 more arguments:
The first argument which is
2
means that the sar command should run every 2 seconds and the second30
means that the command should be executed 30 times.That way you will see on your screen your CPU usage every 2 seconds for 30 times:
If you wanted to check your Memory usage instead, you could use the
-r
argument rather than-u
.Some other useful arguments are
-b
which shows the Disk I/O usage and the-n
which shows the network usage.For more information make sure to check the man pages:
https://manpages.debian.org/testing/sysstat/sar.sysstat.1.en.html
Conclusion
The
sysstat
package also provides you with other useful tools like:iostat
- reports CPU statistics and input/output statistics for block devices and partitions.mpstat
- reports individual or combined processor related statistics.pidstat
- reports statistics for Linux tasks (processes) : I/O, CPU, memory, etc.tapestat
- reports statistics for tape drives connected to the system.cifsiostat
- reports CIFS statistics.Sysstat
- also contains tools you can schedule via cron or systemd to collect and historize performance and activity data:sar
- collects, reports and saves system activity information (see below a list of metrics collected by sar).sadc
- is the system activity data collector, used as a backend for sar.sa1
- collects and stores binary data in the system activity daily data file. It is a front end to sadc designed to be run from cron or systemd.sa2
- writes a summarized daily activity report. It is a front end to sar designed to be run from cron or systemd.sadf
- displays data collected by sar in multiple formats (CSV, XML, JSON, etc.) and can be used for data exchange with other programs. This command can also be used to *draw
- graphs for the various activities collected by sar using SVG (Scalable Vector Graphics) format.If you like the tool make sure to star it on GitHub and contribute:
https://github.com/sysstat/sysstat
Hope that this helps!