20 Useful Commands of ‘Sysstat’ Utilities for Linux Performance Monitoring


Introduction

In world of Linux system administration, performance monitoring is an important task. There are a lot of tools available for this purpose, and one of most widely used is Sysstat utilities. Sysstat utilities are a collection of tools that provide detailed system performance information, including CPU utilization, memory usage, disk activity, and network activity.

In this article, we will explore 20 useful commands of Sysstat utilities for Linux performance monitoring.

Installation of Sysstat Utilities

Before we dive into Sysstat utilities commands, let's first discuss how to install them. Sysstat utilities are typically included in most Linux distributions, so you may not need to install them manually. However, if you do need to install them, you can use following commands −

For Debian-based distributions −

sudo apt-get install sysstat

For Red Hat-based distributions −

sudo yum install sysstat

Top Sysstat utilities commands for performance monitoring

Now that we have an overview of Sysstat utilities, let's explore some of top commands for performance monitoring.

  • sar -u −

    This command provides CPU utilization statistics. "-u" option specifies that we want to see CPU statistics. By default, sar displays CPU usage for all CPUs, but you can specify a specific CPU using "-P" option. For example, to view CPU usage for CPU 0, use following command −

sar -u -P 0
  • sar -r −

    This command provides memory utilization statistics. "-r" option specifies that we want to see memory statistics. By default, sar displays memory usage for all memory types, but you can specify a specific memory type using "-B" option. For example, to view memory usage for buffer cache, use following command −

sar -r -B
  • sar -n DEV −

    This command provides network activity statistics. "-n" option specifies that we want to see network statistics, and "DEV" specifies that we want to see device-specific statistics. By default, sar displays network usage for all devices, but you can specify a specific device using "-I" option. For example, to view network usage for eth0, use following command −

sar -n DEV -I ALL -I SUM -I eth0
  • iostat -x −

    This command provides detailed disk activity statistics, including read and write times, transfer rates, and disk utilization. "-x" option specifies that we want to see extended statistics. By default, iostat displays statistics for all disks, but you can specify a specific disk using "-d" option. For example, to view disk activity for sda, use following command −

iostat -x -d sda
  • pidstat -u −

    This command provides detailed information on individual processes, including CPU usage, memory usage, and I/O activity. "-u" option specifies that we want to see CPU usage statistics. By default, pidstat displays statistics for all processes, but you can specify a specific process using "-p" option. For example, to view process statistics for process ID 1234, use following command −

pidstat -u -p 1234
  • sar -q −

    This command provides load average statistics. "-q" option specifies that we want to see load average statistics. By default, sar displays load averages for last 1, 5, and 15 minutes, but you can specify a different interval using "-s" option. For example, to view load averages for last 10 minutes, use following command −

sar -q -s 10:00:00
  • sar -W −

    This command provides swap utilization statistics. "-W" option specifies that we want to see swap statistics. By default, sar displays swap usage for all devices, but you can specify a specific device using "-p" option. For example, to view swap usage for /dev/sda1, use following command −

sar -W -p /dev/sda1
  • sar -b −

    This command provides block device statistics, including read and write operations and transfer rates. "-b" option specifies that we want to see block device statistics. For example, to view block device statistics for /dev/sda, use following command −

sar -b -p /dev/sda
  • mpstat -P ALL −

    This command provides per-CPU utilization statistics. "-P ALL" option specifies that we want to see CPU statistics for all CPUs. For example, to view CPU statistics for last 5 seconds, use following command −

mpstat -P ALL -I 5
  • iostat -t −

    This command provides timestamp information for disk activity statistics. "-t" option specifies that we want to see timestamps. For example, to view timestamped disk activity for sda, use following command −

iostat -t -d sda
  • pidstat -r −

    This command provides memory utilization statistics for individual processes. "-r" option specifies that we want to see memory statistics. By default, pidstat displays statistics for all processes, but you can specify a specific process using "-p" option. For example, to view memory statistics for process ID 1234, use following command −

pidstat -r -p 1234
  • sar -y −

    This command provides system statistics for TTY devices. "-y" option specifies that we want to see TTY statistics. By default, sar displays statistics for all TTY devices, but you can specify a specific device using "-t" option. For example, to view TTY statistics for tty1, use following command −

sar -y -t tty1
  • sar -n TCP,ETCP −

    This command provides TCP and extended TCP statistics. "-n TCP,ETCP" option specifies that we want to see TCP and extended TCP statistics. By default, sar displays statistics for all TCP connections, but you can specify a specific connection using "-s" option. For example, to view TCP and extended TCP statistics for last hour, use following command −

sar -n TCP,ETCP -s 10:00:00 -e 11:00:00
  • sar -n DEV −

    This command provides network device statistics, including network traffic and errors. "-n DEV" option specifies that we want to see network device statistics.

    For example, to view network device statistics for eth0, use following command −

sar -n DEV -I eth0
  • sar -S −

    This command provides kernel statistics, including context switches and interrupts. "-S" option specifies that we want to see kernel statistics. By default, sar displays statistics for last interval, but you can specify a different interval using "-I" option. For example, to view kernel statistics for last 5 minutes, use following command −

sar -S -I 300
  • sar -A −

    This command provides a summary of all available statistics. "-A" option specifies that we want to see all available statistics. By default, sar displays statistics for last interval, but you can specify a different interval using "-s" and "-e" options. For example, to view a summary of all available statistics for last hour, use following command −

sar -A -s 10:00:00 -e 11:00:00
  • sar -u ALL −

    This command provides CPU utilization statistics for all CPUs. "-u ALL" option specifies that we want to see CPU statistics for all CPUs. For example, to view CPU utilization statistics for all CPUs for last hour, use following command −

sar -u ALL -s 10:00:00 -e 11:00:00
  • sar -P ALL −

    This command provides per-CPU utilization statistics for all CPUs. "-P ALL" option specifies that we want to see CPU statistics for all CPUs. For example, to view per-CPU utilization statistics for all CPUs for last hour, use following command −

sar -P ALL -s 10:00:00 -e 11:00:00
  • sar -r −

    This command provides memory utilization statistics. "-r" option specifies that we want to see memory statistics. For example, to view memory utilization statistics for last hour, use following command −

sar -r -s 10:00:00 -e 11:00:00
  • sar -b −

    This command provides block device statistics, including read and write operations and transfer rates. "-b" option specifies that we want to see block device statistics. By default, sar displays statistics for last interval, but you can specify a different interval using "-s" and "-e" options. For example, to view block device statistics for last hour, use following command −

sar -b -s 10:00:00 -e 11:00:00

Conclusion

In conclusion, sysstat package provides a variety of useful tools for monitoring system performance on Linux systems. With sar, we can monitor CPU, memory, disk, network, and other system resources. ability to view statistics over time, both in real-time and historically, allows us to identify performance issues and potential bottlenecks, making it an essential tool for system administrators and developers alike.

Updated on: 28-Mar-2023

706 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements