Using sar to monitor the GNU / Linux

The utilities package sysstat provides several tools for resource monitoring on GNU / Linux systems.

One such tool is the sar. It shows data from various system counters in real time or data collected through the SADC progam, which is run by the sa1 and sa2 scripts running on cron.

Maintain the history of the use of resources is an important step in the analysis of performance of the servers. Show here as sar can help in this task.

1. Installing the package sysstat

1.1 CentOS 5.7

  yum install sysstat 

After installation, the data already become listed.

1.1.1 Add IO statistics Detailed disk by editing the following file:

  vi / etc / cron.d / sysstat 

1.1.2 Add the-d option in the script sa1:

  * / 10 **** root / usr/lib64/sa/sa1-d 1 1 

These statistics tend to occupy a larger disk space and also have a higher overhead because we are monitoring the disks and using them to record the information generated. Therefore, it is recommended to use this option only if you need to detail the resources for disk and partition. Otherwise, the sar already provides general statistics IO, summarizing the use of all disks.

1.1.3 Adjusting the time history for one month (up to 31 days), editing the file sequinte:

  vi / etc / sysconfig / sysstat 

Change the value of the HISTORY variable, as follows:

  HISTORY = 31 

CentOS in the reports are stored in:

  / Var / log / sa / sa DD 

Where "DD" is the day of the month.

Checking the version:

  # Sar-V
 sysstat version 7.0.2
 (C) Sebastien Godard 

1.2 Debian 6.0

  apt-get install sysstat 

By default, the collection of data is not activated in Debian. To activate it, run the following command, and then select Yes:

  sysstat dpkg-reconfigure 

1.2.1 Add IO statistics Detailed disk by editing the following file:

  vi / etc / default / sysstat 

Modify the script sa1 the option to:

  SA1_OPTIONS = "S-XDISK" 

This option has the same effect as the-d option used on CentOS, however on Debian 6.0 version of sysstat package is more recent, so the change.

Debian already keeps history for a month, which is the maximum supported.

Reports are stored in:

  / Var / log / sysstat / sa DD 

Where "DD" is the day of the month.

Checking the version:

  # Sar-V
 sysstat version 9.0.6.1
 (C) Sebastien Godard (sysstat <at> orange.fr) 

2. Viewing statistics collected

Once collected, data can be read / extracted using the sar command. Here are some options for the most common view. The outputs of the commands are cut with details by way of illustration only.

The meaning of each column can be found in the man page sar , but some columns will destacas most common presentation of commands.

2.1 Displaying CPU statistics

  sar-u
 ...
 10:49:54 CPU% user% nice% system% iowait% steal% idle
 10:50:01 all 0.28 0.07 0.23 0.03 0.00 99.39
 10:50:54 all 0.68 0.03 0.21 0.18 0.00 98.89
 10:51:54 all 0.59 0.03 0.17 0.07 0.00 99.13
 10:52:54 all 0.77 0.03 0.17 0.11 0.00 98.92
 10:53:54 all 1.39 0.04 0.19 0.28 0.00 98.11
 10:54:54 all 1.74 0.03 0.26 0.42 0.00 97.56
 Average: all 1.40 0.03 0.55 1.23 0.00 96.78 

Note that the last line shows the average of the displayed data.

2.2 General Statistics IO (disks)

  sar-b

 ...
 10:49:54 tps rtPS WTPs bread / s bwrtn / s
 10:56:54 148.40 60.47 87.93 1079.20 2670.47
 10:57:54 102.95 13.60 89.35 251.78 2687.08
 10:58:54 53.33 20.98 32.35 345.24 1793.73
 10:59:54 46.53 18.40 28.13 351.47 1651.03
 11:00:01 12.84 7.46 5.37 119.40 387.46
 11:00:54 72.90 18.92 53.98 457.96 2344.41
 11:01:54 127.03 42.67 84.37 737.07 2965.30
 11:02:54 127.04 41.18 85.86 874.16 2313.10
 Average: 333.73 269.65 64.08 36793.14 17341.19 

These disk statistics are generated by default in Debian as well on CentOS. The values ​​shown are for the added use of all disks.

The first data column shows the values ​​of TPS (transfers per second), which represents the total number of data transfers per second, in units of 512 bytes. This value is also known as IOPS (Input / Output Operations Per Second), an extremely important measure in determining bottleneck on the disks.

A first step in determining a possible bottleneck would calculate the nominal IOPS of disk arrays. Then compare the values ​​of tps (general and detailed) reported by sar to get an idea how the current load of the disks. Values ​​greater than the calculated IOPS are possible due to the data cache by both the operating system and the controller. Constant values ​​near the nominal IOPS can indicate serious problems bottleneck on the disks.

This is only one of the points to be considered. Performance analysis of servers includes several aspects that need to be taken into account. How to proceed in such cases is a subject too complex and leave for an upcoming article.

2.3 Detailed Statistics IO (disks)

 sar-dp 11:01:54 rd_sec DEV tps / s wr_sec / s avgrq avgqu-sz-sz await svctm% util sda 11:03:54 12.44 53.61 683.40 59.27 0.03 2.16 11:03:54 sda1 1.26 1.57 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 11:03:54 7.22 0.00 439 sda2, 41 60.88 0.01 1.37 0.12 0.09 11:03:54 sda3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 11:03: sda4 54 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 11:03:54 0.48 sda5 215,24 445,24 0,00 0,00 4,34 11:03:54 sda6 0.52 0.03 4.73 53.61 28.75 17.40 0.01 3.13 3.08 1.46 11:03:54 29.17 440.87 115 sdb, 95 19.09 0.08 2.62 2.19 6.38 11:03:54 sdb1 29.17 440.87 115.95 19.09 0.08 2.62 2.19 6.38 Average: 69 sda , 05 12076.35 8321.86 295.41 0.91 13.22 1.69 11.68 Average: sda1 0.00 0.62 0.00 157.26 0.00 1.65 1.61 0.00 Average: sda2 8.24 140.96 360.38 60.82 0.02 2.25 0.78 0.64 Average: sda3 0.00 0.04 0.02 27.20 0.00 4.51 3, 71 0.00 Average: sda4 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Average: 0.80 0.01 459.13 574.34 sda5 0.02 22 38 0.85 0.07 Average: sda6 60.00 11934.73 7502.34 323.94 0.88 14.61 1.86 11.17 Average: 97.63 6293.25 336.87 67.91 sdb 0.36 3.67 1.59 15.55 Average: sdb1 97.63 6293.25 336.87 67.91 0.36 3.67 1.59 15.55 

These statistics are not generated by default. You need to activate them, as shown earlier.

The-p option shows the names of disk devices.

As we can see, here we have the tps per disk and partition, as well as requests for reading and writing (rd_sec / s, wr_sec / s). Is easier now to identify a disk or partition with IO bottleneck.

2.4 Network Statistics

 sar-n DEV ... 11:05:54 IFACE rxpck / s txpck / s rxbyt / s txbyt / s rxcmp / s txcmp / s rxmcst / s it 66.12 11:05:54 66.12 27142.28 27142 28 11:05:54 eth0 0.00 0.00 0.00 337.11 347.18 62816.76 184603.47 0.00 0.00 0.00 11:05:54 54.83 129.91 eth1 5027.33 173,077.71 0.00 0.00 0.00 Average: lo 45.80 45.80 16683.79 16683.79 0.00 0.00 0.00 Average: eth0 2111.12 4084.43 186005, 46 5,746,933.35 0.00 0.00 0.00 Average: eth1 17.24 31.50 1864.39 40021.03 0.00 0.00 0.00 

2.5 Statistics Memory

  sar-r
 ...
 10:49:54 kbmemfree kbmemused% memused kbbuffers kbcached kbswpfree kbswpused% swpused kbswpcad
 11:15:54 675540 98321864 99.32 102264 86246792 5242484 2728 0.05 100
 11:16:54 1061092 97936312 98.93 102324 86276892 5242484 2728 0.05 100
 11:17:54 1031768 97965636 98.96 102544 86303576 5242484 2728 0.05 100
 11:18:54 940476 98056928 99.05 102616 86347000 5242484 2728 0.05 100
 Average: 764861 98232543 99.23 59250 93499185 5242198 3014 0.06 74 

2.6 Paging memory

  sar-B
 10:49:54 pgpgin / s pgpgout / s fault / s majflt / s
 11:17:54 347.66 728.97 5979.53 0.00
 11:18:54 617.81 428.28 12143.55 0.00
 11:19:54 376.93 347.18 13665.98 0.00
 11:20:01 182.79 175.07 4677.30 0.00
 Average: 8975.72 4241.81 6346.00 0.01 

2.7 Display Options

In addition to the data collected, sar has the option to display real-time data. The following required parameters:

  sar-u 1 10 

The first parameter is the time, the second parameter is a counter. In the example data are displayed in CPU 1 second intervals for a total of 10 times.

When running sar, it always displays the values ​​of the current day. The-f option identifies a day (file) specific month:

  sar-f / var/log/sa/sa10 

And the-s option determines an initial time:

  sar-s 23:00:00 

Combining the two, we obtain values ​​closer to the time of interest:

  sar-f / var/log/sa/sa10-s-u 23:55:00

 23:55:48 CPU% user% nice% system% iowait% steal% idle
 23:56:48 all 1.79 0.03 1.12 2.19 0.00 94.87
 23:57:48 all 3.22 0.03 1.24 0.92 0.00 94.58
 23:58:48 all 2.82 0.03 1.43 1.50 0.00 94.21
 23:59:48 all 3.33 0.03 1.09 0.81 0.00 94.74
 Average: all 2.79 0.03 1.22 1.36 0.00 94.60 

Any of the options presented above can be applied to the above example, allowing filtering by date and time of any data collected. Recalling that the data are stored for up to one month.

Files with the collected data can be copied to another location, thus increasing the time available for historical reference.

References:

Main project site:
http://sebastien.godard.pagesperso-orange.fr

Additional Information:

http://www.thegeekstuff.com/2011/03/sar-examples/

http://sys-log.bencane.com/2012/07/sar-sysstat-linux-performance-statistics-with-ease/

This entry was posted in Linux , Tutorials and tagged , , , . Bookmark the permalink .

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image
Refresh Image

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>