How to Monitor Your Linux Performance With Sysstat

Sysstat is a powerful logging and monitoring tool for Linux/Unix systems. It can be used to monitor system performance and troubleshoot problems. Though many distros have GUI based monitoring applications and API’s, sysstat is a go-to for power users and can log and track pretty much everything going on within your Linux box.

To install sysstat on a RedHat based variant using yum:

yum -y install sysstat

To install on a Debian based variant using apt:

apt-get install sysstat

If you are using a Ubuntu-based distro, you should be able to find sysstat in the software manager.

sysstat-mint-software-manager

After the installation, you will need to edit the configuration file to run the daemon.

In the terminal:

gksu gedit /etc/default/sysstat

and set the “sadc” variable to true by changing the line to ENABLED="true".

sysstat-enable-logging

Save and close the file. Finally, start the daemon:

/etc/init.d/sysstat start

The sysstat suite is obviously a collection of very extensive and detailed application. Here are some basic ways to use the tools in order to gain a feel for its troubleshooting guidance.

Check CPU usage

To check CPU usage stats for the current day (by default sar tracks the data every 10 minutes):

sar -u

To display real-time CPU usage for a given amount of time, you can specify the intervals in seconds followed by how many entries you want to report. For example: the following will report total CPU usage every 2 seconds for a total of 10 times:

sar -u 2 10

sysstat-sar-u-output

Most PCs have multiple cores nowadays. To view the activity of each specific core use the “-P ALL” flag. The following shows a real-time snapshot of the 4 cores in my PC (same intervals and output parameters apply, below is 1 second 1 time):

sar -P ALL 1 1

sysstat-sar-P-ALL-output

Want to see how much memory is currently being used? Use sar -r as follows to show real-time memory usage every 2 seconds for 10 times:

sar -r 2 10

sysstat-sar-r-output

Display device report

To display a device report showing transfers per second (tps) and data read and write stats, showing data in real-time every 2 seconds, for 10 reports, type:

iostat -d 2 10

sysstat-iostat-d results

Note:

  • tps = transfers per second
  • Blk_read/s = amount of data read in blocks per second
  • Blk_wrtn/s = amount of data written in blocks per second
  • Blk_read = total blocks read
  • Blk_wrtn = total blocks written

For extended I/O stats:

iostat -x 2 5

sysstat-iostat-x-results

Get information regarding running process

Use pidstat to report information regarding running process. The -d flag will list all processes on the machine:

pidstat -d

sysstat-pidstat-d-results

To see real-time results of running processes, you can use the following, where like the above examples, the first number is the second interval and the second number is how many times to report:

pidstat - d 2 5

sysstat-pidstat-d25-results

Another useful command is to use pidstat with the -r flag to analyze memory usage with particular processes:

pidstat -r 2 5

sysstat-pidstat-r-results

Sysstat is a very powerful monitoring tool for Linux and it is particularly useful in a server environment where there is no GUI available. The above mentioned only touch the surface of what sysstat is capable. If you have used sysstat in your PC/server, feel free to share with us the various ways you use it to monitor your system performance.