Sar
Monitoring server resources is a crucial part of identifying any bottlenecks and possible issues on your server.
sar stands for “System Activity Reporter” and provides a wide range of metrics related to system usage, including CPU utilization, memory usage, disk I/O, network activity.
on Ubuntu, sar can be installed by following[1]
#install sar
$ sudo apt-get install -y sysstat
# Enable data collecting
sed -i 's/false/true/g' /etc/default/sysstat
# Change the collection interval from every 10 minutes to every 2 minutes
sed -i 's/5-55\/10/*\/2/g' /etc/cron.d/sysstat
# Restart service
$ sudo systemctl start sysstat
sar system service
sar can be run as system service as well,
- sudo systemctl start sysstat
- sudo systemctl enable sysstat
- This will add the required cron jobs so that the system data is collected accordingly. The cron jobs will be added at cat /etc/cron.d/sysstat
Command and options
sar has a lot of arguments and options and basic comman syntax is following,
$ sar -[ options ] time_interval number_of_tines_to_display
$sar --help
Full description is available in sar man page[2]
Here are few examples,
Options | Description | output format |
---|---|---|
sar -u 2 30
|
-u for all CPU,
|
|
sar -r 2 30
|
-r for memory | |
sar -n DEV 4 | -n for network interfaces,
4 means that the sar command should run every 2 seconds |
|
sar -d | -d command to view disk I/O statistics, including IOPS | DEV tps rkB/s wkB/s dkB/s areq-sz aqu-sz await %util
tps is IOPS |