On-Demand sar command usage (Ubuntu 18.04)

ComputerCarriage > Posts > Commands > On-Demand sar command usage (Ubuntu 18.04)
sar command

Use sar -f will get the historic data , example sar -f /var/log/sa/sa10 -r, will show the memory usage for the month day10.

1. sar command

Just typing sar we will get the CPU usage for the current day.

[root@control ~]# sar
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST CPU %user %nice %system %iowait %steal %idle
09:40:01 IST all 1.51 0.00 0.76 0.08 0.00 97.65
09:50:01 IST all 1.79 0.00 0.85 0.03 0.00 97.33
10:00:01 IST all 1.01 0.00 0.62 0.03 0.00 98.34
10:10:01 IST all 0.78 0.00 0.57 0.14 0.00 98.51
Average: all 1.27 0.00 0.70 0.07 0.00 97.96

2. Disk usage check

To check the disk usage use -d option, also it will show each block device that are attached to the node.

[root@control ~]# sar -d
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST DEV tps rkB/s wkB/s areq-sz aqu-sz await svctm %util
09:40:01 IST dev8-0 2.03 22.25 50.47 35.77 0.00 1.53 0.77 0.16
09:40:01 IST dev8-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
09:40:01 IST dev8-32 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
09:40:01 IST dev8-48 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:00:01 IST dev253-0 1.37 0.00 8.58 6.28 0.00 1.65 0.74 0.10
10:00:01 IST dev253-1 0.27 1.07 0.00 4.00 0.00 1.89 0.48 0.01
10:00:01 IST dev253-2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Average: dev8-0 2.46 15.97 27.59 17.74 0.00 1.15 0.64 0.16
Average: dev8-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: dev8-32 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: dev8-48 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: dev253-0 1.45 10.35 8.66 13.08 0.00 1.75 0.74 0.11
Average: dev253-1 6.28 5.62 19.52 4.00 0.01 2.35 0.09 0.05
Average: dev253-2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Important columns that has to be checked

tpsTotal number of transfers per second that were issued tophysical 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.
rkB/sNumber of kilobytes read from the device per second
areq-szThe average size (in kilobytes) of the I/O requests that were issued to the device
aqu-szThe average queue length of the requests that were issued to the device
awaitThe average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them
Columns to be notified

3. Check physical memory usage

We could find the memory usage using -r option, reports memory utilization statistics of the server

[root@control ~]# sar -r
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
09:40:01 IST 99836 102084 1773716 94.67 80 145728 3716472 89.62 816656 846596 24
09:50:01 IST 97392 99720 1776160 94.80 80 145836 3735780 90.09 818776 846816 12
10:00:01 IST 95412 97812 1778140 94.91 80 145924 3736596 90.11 820616 846928 20
10:10:01 IST 108112 110752 1765440 94.23 80 146240 3735708 90.09 799564 855404 24
Average: 100188 102592 1773364 94.65 80 145932 3731139 89.98 813903 848936 20

Important column has to be noted kbmemfree, kbavail, kbmemused, memused, check the available kbmemfree column.

Checking memory usage with Intervals

The -r option in sar used to check the memory usage , in the below example we are going to monitor the memory for 3 intervals , based upon the requirements we can increase the time intervals

[devops@control ~]$ sar -r 1 3
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

10:24:58 IST kbmemfree kbavail kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
10:24:59 IST 97640 109848 1775912 94.79 80 154140 3772332 90.97 849124 812184 24
10:25:00 IST 97640 109848 1775912 94.79 80 154140 3772332 90.97 849124 812184 24
10:25:01 IST 97640 109848 1775912 94.79 80 154140 3772332 90.97 849124 812184 24
Average: 97640 109848 1775912 94.79 80 154140 3772332 90.97 849124 812184 24
[devops@control ~]$

4. Report the CPU usage for all processor

Report per-processor statistics for the specified processor or processors. cpu_list is a list of comma-separated values or range of values (e.g., 0,2,4-7,12-).
Note that processor 0 is the first processor, and processor all is the global average among all processors. Specifying the ALL keyword reports statistics for each individual processor, and globally for all processors. Offline processors are not displayed

[root@control ~]# sar -P ALL
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST CPU %user %nice %system %iowait %steal %idle
09:40:01 IST all 1.51 0.00 0.76 0.08 0.00 97.65
09:40:01 IST 0 1.51 0.00 0.76 0.08 0.00 97.65

09:40:01 IST CPU %user %nice %system %iowait %steal %idle
09:50:01 IST all 1.79 0.00 0.85 0.03 0.00 97.33
09:50:01 IST 0 1.79 0.00 0.85 0.03 0.00 97.33

09:50:01 IST CPU %user %nice %system %iowait %steal %idle
10:00:01 IST all 1.01 0.00 0.62 0.03 0.00 98.34
10:00:01 IST 0 1.01 0.00 0.62 0.03 0.00 98.34

10:00:01 IST CPU %user %nice %system %iowait %steal %idle
10:10:01 IST all 0.78 0.00 0.57 0.14 0.00 98.51
10:10:01 IST 0 0.78 0.00 0.57 0.14 0.00 98.51

Average: CPU %user %nice %system %iowait %steal %idle
Average: all 1.27 0.00 0.70 0.07 0.00 97.96
Average: 0 1.27 0.00 0.70 0.07 0.00 97.96

5. CPU Utilization

To check the real time CPU Utilization -u option is used.

[root@control ~]# sar -u
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST CPU %user %nice %system %iowait %steal %idle
09:40:01 IST all 1.51 0.00 0.76 0.08 0.00 97.65
09:50:01 IST all 1.79 0.00 0.85 0.03 0.00 97.33
10:00:01 IST all 1.01 0.00 0.62 0.03 0.00 98.34
10:10:01 IST all 0.78 0.00 0.57 0.14 0.00 98.51
10:20:01 IST all 1.07 0.02 0.67 0.07 0.00 98.17
Average: all 1.23 0.00 0.69 0.07 0.00 98.00

Other few options that are be used

sar -u 1 10 Displays real time CPU usage every 1 second for 10 times.
sar -u -f /var/log/sa/sa10 display CPU usage for the 10th day of the month from the sa10 file.

6. Hugepages utilization statistics

The huge page ulilization is used to analyse the virtual memory management in the server, for example we can set the huge page size for the application to 500MB for example, at OS boot the memory is allocated for the application to use.

[devops@control ~]$ sar -H
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST kbhugfree kbhugused %hugused
09:40:01 IST 0 0 0.00
09:50:01 IST 0 0 0.00
10:00:01 IST 0 0 0.00
10:10:01 IST 0 0 0.00
10:20:01 IST 0 0 0.00
Average: 0 0 0.00
[devops@control ~]$

7. Reporting page statictics

To report the paging statistics -b option is used.

[devops@control ~]$ sar -b
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST tps rtps wtps bread/s bwrtn/s
09:40:01 IST 2.03 0.65 1.38 44.50 100.94
09:50:01 IST 1.25 0.04 1.21 1.07 14.54
10:00:01 IST 1.39 0.13 1.26 2.15 16.02
10:10:01 IST 5.14 3.70 1.44 80.04 89.19
10:20:01 IST 2.80 1.32 1.48 92.76 117.50
Average: 2.52 1.17 1.36 44.10 67.64
[devops@control ~]$

8. SWAP Utilization

Report swap space utilization statistics -S option is used, important columns to be notified kmswpused and %swpused.

[devops@control ~]$ sar -S
Linux 4.18.0-147.8.1.el8_1.x86_64 (control.balapobi.com) Tuesday 12 May 2020 x86_64 (1 CPU)

09:30:01 IST kbswpfree kbswpused %swpused kbswpcad %swpcad
09:40:01 IST 1838588 434688 19.12 57376 13.20
09:50:01 IST 1838844 434432 19.11 57528 13.24
10:00:01 IST 1839612 433664 19.08 57320 13.22
10:10:01 IST 1821692 451584 19.86 60708 13.44
10:20:01 IST 1797628 475648 20.92 48304 10.16
Average: 1827273 446003 19.62 56247 12.61
[devops@control ~]$

Refer sar manual https://linux.die.net/man/1/sar

Also refer Quick Health check on linux server https://computercarriage.com/2020/05/18/quick-health-check-on-linux-servers/

One thought on “On-Demand sar command usage (Ubuntu 18.04)

Leave a Reply