The tools that we have looked at so far are fantastic to analyze problems that are present now; but what about when you need to look at issues that occurred in the past? For that you can use the System Activity Report (SAR) tool. Using the sar
tool, you will be able to look back over a period of time and see how the server has been running.
This recipe will demonstrate how to install and use the sysstat
tools; thus, allowing you to examine historical system statistics.
Let's take a look at how to install and use sysstat
, also allowing you to examine historical SAR:
Install the
sysstat
package using the following command for a Debian-based distribution:$ sudo apt-get install sysstat
We can also use the following command for a RHEL-based distribution:
$ sudo yum install sysstat
Edit the
/etc/default/sysstat
file with your favorite text editor and change the following value from:ENABLED="false"
To:
ENABLED="true"
Restart the
sysstat
service using the following command:$ sudo service sysstat restart
By default,
sar
stats are collected every 10 minutes. The data is collected using a simple cron job configured within/etc/cron.d/sysstat
. This job can be amended to collect the data as frequently as you require.Use the following command to view basic CPU statistics, including wait times:
sar -u
This should produce the following output:
Use the following command to view the available memory statistics:
sar -r
This should produce an output that looks similar to the following screenshot:
Seeing the IO stats for individual block devices can be helpful when tracking down performance issues. You can use the following command to view these statistics with
sar
:sar -b
This will produce an output similar to the following screenshot: