Sysstat A Tutorial on Installation and Usage

By Chandrashekhar Fakirpure

Updated on May 10, 2024

In this tutorial, we'll learn monitoring system resources with Sysstat A Tutorial on Installation and Usage. Sysstat is a powerful tool monitor various system resources such as CPU utilization, memory usage, disk I/O activity, and more. In a Linux environment, keeping track of system resource usage is crucial for maintaining optimal performance and diagnosing issues.

Let's get started.

1. Installing Sysstat:

We can install it using your distribution's package manager. For example, on Debian/Ubuntu, you can run:

sudo apt-get update
sudo apt-get install sysstat

On CentOS/RHEL/AlmaLinux/Rocky Linux, you can use:

sudo dnf install sysstat

Start and enable sysstat service using following command:

systemctl start sysstat && systemctl enable sysstat

Ensure that the package is successfully installed by running sar or mpstat commands.

2. Configuring Sysstat:

By default, Sysstat is configured to collect system statistics every 10 minutes. We can adjust the collection interval. To change the interval time to 1 miniute:

nano /etc/systemd/system/sysstat.service.wants/sysstat-collect.timer

Change the line:

[Timer]
OnCalendar=*:00/10

To:

[Timer]
OnCalendar=*:00/1

Reload systemctl daemon:

systemctl daemon-reload

Restart sysstat service:

systemctl restart sysstat

We can find sysstat configuration file here /etc/sysstat/sysstat.

3. Viewing System Resource Statistics:

Once Sysstat is installed and configured, you can view system resource statistics using various commands provided by the package.
The sar command is used to display system activity reports. You can use it to view CPU utilization, memory usage, disk I/O statistics, and more.

To view CPU utilization:

sar -u

To view memory usage:

sar -r

To view disk I/O statistics:

sar -d

Additionally, you can use the mpstat command to display CPU usage statistics.

mpstat

This command provides network statistics such as network interface activity, errors, and packet statistics.

sar -n DEV

Displays I/O and transfer rate statistics for block devices.

sar -b

Shows the system load average and the number of processes in the run queue.

sar -q

Displays information about swapping and switching activity.

sar -w

Provides statistics about the TTY devices.

sar -y

Shows CPU utilization statistics for all CPUs individually.

sar -u ALL

Displays swap utilization statistics.

sar -S

Shows memory pages swapped in and out per second.

sar -R

Provides per-CPU statistics for various activities such as CPU utilization, interrupts, context switches, etc.

sar -P ALL

Provides all available system activity information.

sar -A

4. Generating Reports:

Sysstat also provides tools to generate reports based on collected data.
You can use the sadf command to convert binary data files generated by Sysstat into various formats such as CSV or XML.

sadf -dh /var/log/sysstat/sa<date> > monitor_report.csv

Note: <date> is the day of the date.

To generate daily summary reports, you can use the sar command with the -f option.

sar -f /var/log/sysstat/sa<date> > monitor_report.csv

Note: <date> is the day of the date.

5. Automating Data Collection:

To automate the collection of system resource statistics, you can use the cron scheduler.

Sysstat comes with a cron job file that is usually located at /etc/cron.d/sysstat. This file defines the schedule for running the Sysstat data collection script (/usr/lib/sysstat/sa1) periodically. You can adjust the schedule in the cron job file if needed.

Conclusion:

We have seen monitoring system resources with Sysstat A Tutorial on Installation and Usage. Sysstat is a valuable tool for monitoring system resource usage in Linux environments. By installing and configuring Sysstat, you can gain insights into CPU utilization, memory usage, disk I/O activity, and other important metrics.

With the ability to generate reports and automate data collection, Sysstat helps sysadmins maintain system performance and troubleshoot issues effectively.