In this guide I will be showing you how to install and enable the SAR utility/command on Linux servers. The SAR command can be used to look at performance history, and is really useful for identifying when CPU spikes occurred and more. And example of one of the outputs that SAR is capable of delivering is below.
root@teachmelinux:~# sar -p Linux 4.4.0-93-generic (teachmelinux) 09/07/2017 _x86_64_ (1 CPU) 11:22:27 PM LINUX RESTART (1 CPU) 11:24:01 PM CPU %user %nice %system %iowait %steal %idle 11:26:01 PM all 3.66 0.00 0.79 0.33 0.04 95.18 11:28:01 PM all 0.72 0.00 0.17 0.07 0.03 99.02 11:30:01 PM all 2.37 0.00 0.48 0.15 0.06 96.94 11:32:01 PM all 2.01 0.00 0.48 0.16 0.08 97.26 11:34:01 PM all 5.65 0.00 1.13 0.33 0.08 92.82 11:36:01 PM all 2.85 0.00 0.59 0.31 0.07 96.18 11:38:01 PM all 3.06 0.00 0.62 0.17 0.03 96.12 Average: all 2.90 0.00 0.61 0.22 0.06 96.22
To install sysstat (contains SAR) and any dependencies you can use one of the following commands depending on your distribution.
For Red Hat, CentOS, and Fedora you will use the following yum command to install sysstat.
sudo yum install sysstat -y
For Ubuntu, Debian, and other distributions based on the two, you will use the following apt-get command to install SAR.
sudo apt-get install sysstat -y
Enabling SAR Command
If you are running RHEL and possibly CentOS or Fedora, then you should be set, if you are running a Debian or Ubuntu based OS though then you will still need to enable it. You can do so by running the command below or manually editing the file /etc/default/sysstat.
sudo echo 'ENABLED="true"' > /etc/default/sysstat
Next you will need to restart the actual service which can be done with either of the following commands (second command depends on if your system still uses init.d or not).
sudo service sysstat restart OR sudo /etc/init.d/sysstat restart
Congratulations, everything is now setup and working. Please note that SAR may not show any results right away, by default it grabs the systems information every 10 minutes.
I hope this quick and easy guide was useful, please don’t forget to like/comment/share, thanks!