Monitoring servers are very important for every server administrator. There are some command line tools available to monitor server resource usages like top, vmstat, etc.
SAR or sar provides almost all the resource usages reports which we get from many different tools at one place but more importantly is could keep a record of the data which can be used for historical analysis to identify bottlenecks. With the tool, you can check the performance report of a specific time.
Installation is pretty simple, you just need to install sysstat tool using apt as below:
sudo apt-get install sysstat
After we have installed sar we will need to configure it to collect and store performance data on a regular interval.
To do that we will enable sadc by modifying configuration file “/etc/default/sysstat”
sudo vi /etc/default/sysstat
# Should sadc collect system activity informations? Valid values # are "true" and "false". Please do not put other values, they # will be overwritten by debconf! ENABLED="true"
After this, a cronjob will start collecting the SAR report every 10 min, but we would want that report to be collected much sooner so we will change the cronjob to run every min:
sudo vi /etc/cron.d/sysstat
# Activity reports every 10 minutes everyday * * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
That is All! We now have a working SAR tool which records all performance related data.
You can now use the sar command to get the performance report as below:
Some important command line option which we can use:
-u CPU Usage of ALL CPUs
-q Reports run queue and load average
-r Memory Free and Used
-S Swap Space Used
-b Overall I/O Activities
-d Individual Block Device I/O Activities
-n Report network statistics
You can set repetition and interval with any command for desired output:
sar[ interval [ count ]]
You can now check the reports that have been collected in the past by specifying time and day:
-s hh:mm[:ss] start time
-e hh:mm[:ss] end time
-f /var/log/sysstat/sa[DD] on a specific day,
Note: If you have just installed and configured the sar you might not get the directory, full day report get written to the folder in midnight.
Please refer the man page of sar for more options. Thanks for your time!