Collect and report Linux System Activity Information with sar

From Thomas-Krenn-Wiki
Jump to navigation Jump to search

Under Linux, sar serves to log and evaluate a variety of information regarding system activity. With performance problems, sar also permits retroactive analysis of the load values for various sub-systems (CPUs, memory, disks, interrupts, network interfaces and so forth) and limitation of problems in this manner.

Construction

sar is a component of sysstat.[1] sar itself consists of the following components:

  • sar(1) – displays the recorded data.
  • sadc(8) - system activity data collector, which records the data regarding system activity in a binary format.
  • sa1(8) – a BASH script used by sadc in background; called every ten minutes by cron (from /etc/cron.d/sysstat).
  • sa2(8) – a BASH script used for writing the daily reports and called by cron once per day (from /etc/cron.d/sysstat).
  • sadf(1) – displays the recorded data; in contrast with sar provides various formats (CSV, XML and so forth).

Versions

Development of the sysstat package (which contains sar among others) is ongoing. The following schema is used for the version numbers:[2]

  • Version numbers with x.0 each indicate a stable version
  • Version numbers with x.1 each indicate a version in development

Newer versions generally provide additional features. The features of sar -x and sar -X were exported to a separate command as of version 7.1.6 (pidstat).[3]

Installation

As noted, sar is a component of the sysstat package, which is already contained in numerous distribution files and can be easily installed, depending on the distribution file, either by yum install sysstat or apt-get install sysstat. Generally at the same time, the cron jobs will be created in /etc/cron.d/sysstat.

Functional Approach of Logging

sa1 and sa2 will store the recorded data in the directories, /var/log/sa/ (RHEL/CentOS) or /var/log/sysstat/ (Debian). The data will be retained for a week retroactively in the default configuration. This duration can be increased to 28 days (in /etc/sysconfig/sysstat under RHEL/CentOS or in /etc/sysstat/config under Debian 4.0 and /etc/sysstat/sysstat under Debian 5.0).

Activating sar Logging in Debian: To activate automatic logging under Debian, the "ENABLED" parameters must be set to "true" in the /etc/default/sysstat file. This parameter has been set to "false" by default.

Here is an example of this:

[root@testserver ~]# cat /etc/sysconfig/sysstat
# How long to keep log files (days), maximum is a month
HISTORY=7
[root@testserver ~]# cat /etc/cron.d/sysstat 
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 1 1
# generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A

[root@testserver ~]# ls -l /var/log/sa/
total 8952
-rw-r--r--  1 root root 410352 May 18 23:50 sa18
-rw-r--r--  1 root root 410352 May 19 23:50 sa19
-rw-r--r--  1 root root 410352 May 20 23:50 sa20
-rw-r--r--  1 root root 410352 May 21 23:50 sa21
-rw-r--r--  1 root root 410352 May 22 23:50 sa22
-rw-r--r--  1 root root 410352 May 23 23:50 sa23
-rw-r--r--  1 root root 410352 May 24 23:50 sa24
-rw-r--r--  1 root root 410352 May 25 23:50 sa25
-rw-r--r--  1 root root 253712 May 26 14:40 sa26
-rw-r--r--  1 root root 611085 May 17 23:53 sar17
-rw-r--r--  1 root root 611129 May 18 23:53 sar18
-rw-r--r--  1 root root 611127 May 19 23:53 sar19
-rw-r--r--  1 root root 611127 May 20 23:53 sar20
-rw-r--r--  1 root root 611085 May 21 23:53 sar21
-rw-r--r--  1 root root 611100 May 22 23:53 sar22
-rw-r--r--  1 root root 611085 May 23 23:53 sar23
-rw-r--r--  1 root root 611085 May 24 23:53 sar24
-rw-r--r--  1 root root 611125 May 25 23:53 sar25
[root@testserver ~]#

Displaying the recorded data using sar

Limiting the Display Period

sar can display either the data for the current day (which does not require any special parameters) or the data for a specific day (such as with the -f /var/log/sa/sa21 parameter).

The query period can be further limited by the following parameters:

  • -s [ hh:mm:ss ] - sets the starting time (such as -s 07:30:00); if a specific time is not specified, 08:00:00 will be used as the default starting time.
  • -s [ hh:mm:ss ] - sets the ending time (such as -s 19:30:00); if a specific time is not specified, 18:00:00 will be used as the default ending time.

Parameters for Various Sub-systems

Here are several examples for displaying various values (the values originated on a system using CentOS 4.7 with sysstat version 5.0.5).

Displaying the CPU Load: sar -P ALL

The values for all CPUs (-P ALL) will be displayed starting from the 25th of the current month (-f /var/log/sa/sa25).

[root@testserver ~]# sar -P ALL -f /var/log/sa/sa25
Linux 2.6.9-023stab048.6-smp (testserver.thomas-krenn.com) 	05/25/09

00:00:01          CPU     %user     %nice   %system   %iowait     %idle
00:10:01          all      9.63      0.00      3.81      6.20     80.36
00:10:01            0      8.69      0.00      3.63      7.18     80.50
00:10:01            1      9.28      0.00      3.96      4.47     82.29
00:10:01            2     10.22      0.00      3.86      6.31     79.62
00:10:01            3      9.84      0.00      3.66      6.91     79.59
00:10:01            4      9.86      0.00      3.94      5.28     80.92
00:10:01            5      9.97      0.00      3.84      6.37     79.81
00:10:01            6      9.90      0.00      4.04      7.21     78.85
00:10:01            7      9.32      0.00      3.54      5.83     81.32
[...]
Average:          all      9.21      0.00      1.68      0.27     88.84
Average:            0      9.03      0.00      1.70      0.31     88.97
Average:            1      9.20      0.00      1.67      0.25     88.88
Average:            2      9.45      0.00      1.70      0.28     88.56
Average:            3      9.84      0.00      1.68      0.26     88.22
Average:            4      9.23      0.00      1.68      0.26     88.84
Average:            5      9.05      0.00      1.68      0.27     89.00
Average:            6      8.90      0.00      1.68      0.29     89.14
Average:            7      8.97      0.00      1.66      0.28     89.10
[root@testserver ~]#

Displaying the RAM Load: sar -r

The RAM values (-r) for the current day will be displayed here. A value of approximately 100 for the percentage of memory used is thoroughly positive (if swapping is not required). See also the Operating System Caches section of the RAID Controller and Hard Disk Cache Settings article.

[root@testserver ~]# sar -r
Linux 2.6.9-023stab048.6-smp (testserver.thomas-krenn.com)   05/26/09

00:00:01    kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused  kbswpcad
00:10:01        67248  16292680     99.59     42320  12502420   2047648       628      0.03         0
00:20:01       129776  16230152     99.21     47020  12527100   2047648       628      0.03         0
[...]
14:50:01       638680  15721248     96.10    158392   6953128   2047648       628      0.03         0
15:00:01       646272  15713656     96.05    159880   6966980   2047648       628      0.03         0
15:10:01        59784  16300144     99.63    132044   6565036   2047648       628      0.03         0
Average:       554290  15805638     96.61    124889  10992802   2047648       628      0.03         0
[root@testserver ~]# 

Displaying the Load Average: sar -q

The average load values (-q) for the current day will be displayed here.

[root@testserver ~]# sar -q 
Linux 2.6.9-023stab048.6-smp (testserver.thomas-krenn.com) 	05/26/09

00:00:01      runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15
00:10:01            0       590      1.62      1.89      1.21
00:20:01           11       574      0.24      0.63      0.86
[...]
15:10:01            7       671      2.36      2.26      2.03
15:20:01            9       651      1.85      1.96      1.99
Average:            7       600      1.02      1.04      1.00
[root@testserver ~]# 

Displaying the I/O Transfer Rate: sar -b

The I/O transfer rates (-r) for the current day will be displayed here.

[root@testserver ~]# sar -b
Linux 2.6.9-023stab048.6-smp (testserver.thomas-krenn.com) 	05/26/09

00:00:01          tps      rtps      wtps   bread/s   bwrtn/s
00:10:01       402.21    197.20    205.00  35133.80  27616.04
00:20:01        66.61     56.36     10.24   2034.96    288.93
[...]
15:20:01        72.43      6.54     65.89    176.29   2720.35
15:30:01        73.28      6.08     67.20    399.04   3516.21
Average:        40.21      5.57     34.64    585.00   1561.78
[root@testserver ~]# 

tps - Total number of transfers per second that were issued to physical devices. A transfer is an I/O request to a physical device. Multiple logical requests can be combined into a single I/O request to the device. A transfer is of indeterminate size

rtps - Total number of read requests per second issued to physical devices

wtps - Total number of write requests per second issued to physical devices

bread/s - Total amount of data read from the devices in blocks per second. Blocks are equivalent to sectors with 2.4 kernels and newer and therefore have a size of 512 bytes. With older kernels, a block is of indeterminate size.

bwrtn/s - Total amount of data written to devices in blocks per second.

Displaying the Network Statistics: sar -n DEV

The statistical network values (-n) for the current day will be displayed here.

[root@testserver ~]# sar -n DEV
Linux 2.6.9-023stab048.6-smp (testserver.thomas-krenn.com) 	05/26/09

00:00:01        IFACE   rxpck/s   txpck/s   rxbyt/s   txbyt/s   rxcmp/s   txcmp/s  rxmcst/s
00:10:01           lo      0.82      0.82    177.69    177.69      0.00      0.00      0.00
00:10:01         eth0     31.56     40.21   4537.41  35891.07      0.00      0.00      0.00
00:10:01         eth1   4876.29   9919.22 451754.61 14927283.09      0.00      0.00      0.00
00:10:01       venet0     52.88     44.19  46547.68  15279.15      0.00      0.00      0.00
[...]
15:30:01           lo      0.82      0.82    176.68    176.68      0.00      0.00      0.00
15:30:01         eth0    113.08    155.70  17825.90 188643.77      0.00      0.00      0.00
15:30:01         eth1    634.80   1268.92  58495.76 1888004.02      0.00      0.00      0.00
15:30:01       venet0    189.86    147.08 213164.21  42532.10      0.00      0.00      0.00
Average:           lo      0.82      0.82    177.10    177.10      0.00      0.00      0.00
Average:         eth0     56.42     78.90   9104.66  94428.28      0.00      0.00      0.00
Average:         eth1    281.59    559.55  25919.74 830592.96      0.00      0.00      0.00
Average:       venet0     87.26     64.75  99974.13  14933.05      0.00      0.00      0.00
[root@testserver ~]# 

Displaying All Values

The collective values for all devices (CPU, RAM, etc.) can be displayed using sar -A.

Tools for Visual Assessment

The following tools represent the values recorded by sar visually.

References


Foto Werner Fischer.jpg

Author: Werner Fischer

Werner Fischer, working in the Knowledge Transfer team at Thomas-Krenn, completed his studies of Computer and Media Security at FH Hagenberg in Austria. He is a regular speaker at many conferences like LinuxTag, OSMC, OSDC, LinuxCon, and author for various IT magazines. In his spare time he enjoys playing the piano and training for a good result at the annual Linz marathon relay.


Related articles

Check TCP Port 80 (http) with telnet
Linux Kernel Versions
Predictable Network Interface Names