×


Monitor Linux performance using sysstat tool

Sysstat is a robust logging and performance monitoring utility for Linux/Unix systems. It can be used to keep track of system performance and usage activity.

Sysstat saves the statistics collected in a file that can be exported into various formats such as JSON, CSV, etc. Though many Linux distributions include GUI-based monitoring apps, sysstat is especially useful in a server setting.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux system Monitoring queries.

In this context, we shall look into how to use the sysstat tool to collect key system information on Linux.

For further information on Systat, check out the Sysstat Documentation http://sebastien.godard.pagesperso-orange.fr/documentation.html.


How to install Sysstat ?

The Sysstat package is available in the default package repositories and may be installed with the commands below:

$ sudo apt install sysstat


Common usage of Sysstat

The sysstat suite comprises various tools that help collect information on CPU and I/O statistics. Here, we will discuss how to use the tools to get system information. These tools include:

  • iostat – shows an overview of CPU and I/O statistics for drives and partitions
  • mpstat– displays processor statistics.
  • pidstat – gives an overview of I/O, memory statistics for processes.
  • sar – used for collecting and saving all the system activities and reports.
  • sadc- collects system usage activity and writes it to a file.


1.  How to Check CPU usage ?

Sars is used to collect system statistics such as CPU utilization, memory among others. View your CPU utilization statistics for the day. Sar monitors data every 10 minutes by default:

$ sar -u

To display real-time CPU utilization for a set period of time, specify the intervals in seconds followed by the number of entries to report. For instance, to view total CPU utilization every 3 seconds for a total of 15 times run:

$ sar -u 3 15


2. How to Check individual CPU usage ?

Currently, the majority of PCs have several cores. To display the statistics of each core use the sars command followed by the "-P ALL" parameter as shown below:

$ sar -P ALL 1 1

This will display the system's four cores with the same time interval and output parameters applied.


3. How to Check memory usage ?

To display the amount of memory in use at a particular time use the -r option:

$ sar -r


4. How to Display device report ?

Use the iostat command to display a device report showing current data transfer per second (tps), average block rate, and data read and write statistics. Run the following command:

$ iostat -d

The columns in the output represent:

  • tps – transfers per second issued on the device
  • kB_read/s – shows the amount of kilobytes read in blocks per second
  • kB_wrtn/s – the amount of data written to devices in kbs per second
  • kB_read – total kilobytes read
  • kB_wrtn – total number of kilobytes written

To view extended I/O statistics run:

$ iostat -x


How to View current processes ?

The pidstat command is used to keep track of each individual task managed by the kernel. To get information about the running processes, run the pidstat command followed by -d parameter:

$ pidstat -d

You can also pidstat with the -r option to analyze memory usage with particular processes:

$ pidstat -r


[Need assistance in fixing Linux system issues ? We can help you. ]


Conclusion

This article covers how to install Linux Sysstat Utilities For Monitoring System Performance. In fact, Sysstat is a powerful monitoring tool for Linux environments. 

Basically, Sysstat is actually a collection of utilities designed to collect information about the performance of a Linux installation and record them over time.


Main features of Sysstat:

  • Display average statistics values at the end of the reports.
  • On-the-fly detection of new devices (disks, network interfaces, etc.) that are created or registered dynamically.
  • Support for UP and SMP machines, including machines with hyperthreaded or multi-core processors.
  • Support for hotplug CPUs (it detects automagically processors that are disabled or enabled on the fly) and tickless CPUs.
  • Works on many different architectures, whether 32- or 64-bit.
  • Needs very little CPU time to run (written in C).
  • System statistics collected by sar/sadc can be saved in a file for future inspection. You can configure the length of data history to keep. There is no limit for this history length but the available space on your storage device.
  • System statistics collected by sar/sadc can be exported in various different formats (CSV, XML, JSON, SVG, etc.). DTD and XML Schema documents are included in sysstat package. JSON output format is also available for mpstat and iostat commands.
  • iostat can display statistics for devices managed by drivers in userspace like spdk.
  • Smart color output for easier statistics reading.

Different methods of installing Sysstat on any Linux distribution ?

1. Install from RHEL/Fedora/CentOS

Execute:

$ sudo yum install sysstat

CentOS and Fedora systems call the collector process using a cron job in /etc/cron.d and it's enabled by default. On recent versions, systemd is used instead of cron. You may need to enable and start the sysstat service:

$ sudo systemctl enable sysstat
$ sudo systemctl start sysstat


2. Install from Ubuntu

Execute:

$ sudo apt-get install sysstat

Then enable data collecting:

$ sudo vi /etc/default/sysstat

change ENABLED="false" to ENABLED="true"

save the file

Last, restart the sysstat service:

$ sudo service sysstat restart


3. Install Sysstat from sources

Clone sysstat public repository with:

$ git clone git://github.com/sysstat/sysstat

Then configure sysstat for your system:

$ cd sysstat
$ ./configure

You can set several variables and parameters on the command line. For example you can enter the following option to activate data collecting (either using cron or systemd):

$ ./configure --enable-install-cron

Enter ./configure --help to display all possible options.

Finally, Compile and install:

$ make
$ sudo make install