Most Linux administrator monitor system performance with SAR report because it collects performance data for a week.
But you can easily extend this to four weeks by making changes to the “/etc/sysconfig/sysstat” file.
Also, this period can be extended beyond one month. If the value exceeds 28, the log files are placed in multiple directories, one for each month.
To extend the coverage period to 28 days, make the following change to the “/etc/sysconfig/sysstat” file.
Edit the sysstat file and change HISTORY=7 to HISTORY=28.
In this article we have added three bash scripts that will help you to easily view each data file averages in one place.
Script-1: Bash Script to Get Average CPU Utilization from SAR Reports
This bash script collects the CPU average from each data file and display it on one page.
Since this is a month end, it shows 28 days data for October 2019.
# nano /usr/src/sar-cpu-avg.sh #!/bin/sh echo "+----------------------------------------------------------------------------------+" echo "|Average: CPU %user %nice %system %iowait %steal %idle |" echo "+----------------------------------------------------------------------------------+" for file in `ls -tr /var/log/sa/sa* | grep -v sar` do dat=`sar -f $file | head -n 1 | awk '{print $4}'` echo -n $dat sar -f $file | grep -i Average | sed "s/Average://" done echo "+----------------------------------------------------------------------------------+"
Once you run the script, you will get an output like the one below.
# sh /usr/src/sar-cpu-avg.sh +----------------------------------------------------------------------------------+
|Average: CPU %user %nice %system %iowait %steal %idle |
+----------------------------------------------------------------------------------+
10/10/2019 all 6.78 0.08 2.15 0.32 0.00 90.67
10/11/2019 all 6.90 0.08 2.18 0.32 0.00 90.52
10/12/2019 all 7.42 0.08 2.30 0.28 0.00 89.93
10/13/2019 all 8.96 0.08 2.78 0.22 0.00 87.95
10/14/2019 all 7.78 0.08 2.55 0.27 0.00 89.32
10/15/2019 all 7.32 0.08 2.37 0.34 0.00 89.88
10/16/2019 all 8.45 0.08 2.65 0.26 0.00 88.56
10/17/2019 all 7.46 0.08 2.47 0.25 0.00 89.74
10/18/2019 all 7.16 0.08 2.37 0.30 0.00 90.09
10/19/2019 all 6.90 0.08 2.30 0.28 0.00 90.44
10/20/2019 all 7.05 0.08 2.34 0.32 0.00 90.21
10/21/2019 all 6.93 0.08 2.33 0.39 0.00 90.28
10/22/2019 all 7.39 0.08 2.61 0.36 0.00 89.57
10/23/2019 all 7.26 0.08 2.49 0.28 0.00 89.88
10/24/2019 all 6.61 0.08 2.25 0.26 0.00 90.80
10/25/2019 all 9.45 0.08 3.05 0.40 0.00 87.02
10/26/2019 all 8.51 0.08 2.80 0.34 0.00 88.27
10/27/2019 all 8.52 0.08 2.73 0.37 0.00 88.30
10/28/2019 all 7.37 0.08 2.41 0.34 0.00 89.80
10/29/2019 all 8.56 0.08 2.63 0.26 0.00 88.47
10/30/2019 all 8.30 0.08 2.64 0.31 0.00 88.67
10/31/2019 all 10.78 0.11 3.38 0.34 0.00 85.39
11/01/2019 all 13.24 0.12 4.40 0.48 0.00 81.76
all 12.01 0.11 3.62 0.18 0.00 84.07
11/02/2019 all 9.65 0.09 3.07 0.66 0.00 86.53
11/03/2019 all 9.19 0.08 2.77 0.44 0.00 87.51
11/04/2019 all 8.01 0.09 2.72 0.39 0.00 88.80
11/05/2019 all 8.12 0.08 2.58 0.32 0.00 88.90
11/06/2019 all 8.63 0.08 2.67 0.23 0.00 88.38
11/07/2019 all 8.85 0.08 2.78 0.31 0.00 87.99
11/08/2019 all 7.76 0.10 2.52 0.35 0.00 89.27
+----------------------------------------------------------------------------------+
Script-2: Bash Script to Get Average Memory Utilization from SAR Reports
This bash script will collect memory averages from each data file and display it on one page.
Since this is a month end, it shows 28 days data for October 2019.
# nano /usr/src/sar-memory-avg.sh #!/bin/sh echo "+-------------------------------------------------------------------------------------------------------------------+" echo "|Average: kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty |" echo "+-------------------------------------------------------------------------------------------------------------------+" for file in `ls -tr /var/log/sa/sa* | grep -v sar` do dat=`sar -f $file | head -n 1 | awk '{print $4}'` echo -n $dat sar -r -f $file | grep -i Average | sed "s/Average://" done echo "+-------------------------------------------------------------------------------------------------------------------+"
Once you run the script, you will get an output like the one below.
# sh /usr/src/sar-memory-avg.sh +-------------------------------------------------------------------------------------------------------------------+
|Average: kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty |
+-------------------------------------------------------------------------------------------------------------------+
10/10/2019 12312276 119431544 90.65 14301606 55097129 32850058 24.15 74563160 15892561 1386
10/11/2019 11722388 120021432 91.10 15606065 53726048 33069796 24.31 74440196 16184202 2535
10/12/2019 7528717 124215103 94.29 17383309 58255871 33387933 24.54 82523775 14803132 2753
10/13/2019 4940873 126802947 96.25 18813709 60655162 33584827 24.69 87180531 14859281 1941
10/14/2019 13181852 118561968 89.99 15904026 54476373 34005129 25.00 76499728 16624089 3827
10/15/2019 10871398 120872422 91.75 16652963 54448343 33788597 24.84 76567220 17399517 1282
10/16/2019 7189862 124553958 94.54 18132502 57779226 33939604 24.95 84022230 15194380 1379
10/17/2019 10404019 121339801 92.10 17315784 55359236 33795913 24.84 81126418 15034694 1779
10/18/2019 14000822 117742998 89.37 16837215 50981214 33924874 24.94 76966923 14527783 956
10/19/2019 6370503 125373317 95.16 17698805 57832326 33842028 24.88 85522640 13940747 1738
10/20/2019 7291460 124452360 94.47 12701451 74599233 33893523 24.91 62830043 49226962 2256
10/21/2019 11724400 120019420 91.10 16891510 55697613 34331659 25.24 75408309 22880495 2424
10/22/2019 17245409 114498411 86.91 14795834 49401173 34399054 25.29 75461066 14761475 2138
10/23/2019 8993274 122750546 93.17 16542702 56843383 34994497 25.72 80712204 18442444 1766
10/24/2019 10747969 120995851 91.84 16093379 54953646 34773150 25.56 79000442 17933454 14416
10/25/2019 15776354 115967466 88.02 14306792 50394104 35403710 26.02 74583338 16564799 1880
10/26/2019 13207529 118536291 89.97 14227138 53028684 35115592 25.81 76154184 17411955 2460
10/27/2019 19088684 112655136 85.51 13169245 47382031 35549133 26.13 73404318 13605015 1896
10/28/2019 13875582 117868238 89.47 13469267 51415456 35296664 25.94 74228514 17016729 7389
10/29/2019 7747733 123996087 94.12 14711803 57630856 35506177 26.10 81411890 17332323 2279
10/30/2019 6999129 124744691 94.69 15683817 59585379 35430046 26.04 88275868 13486514 2023
10/31/2019 6236615 125507205 95.27 18223859 65999083 35226587 25.89 89549970 13816035 1280
11/01/2019 11010570 120733250 91.64 19965391 56848430 36263313 26.66 69856237 27658758 27791
74802579 56941241 43.22 97804 36513939 31507353 23.16 36211855 17475702 391
11/02/2019 11757377 119986443 91.08 15601489 57674619 31431251 23.10 55627485 36477943 1465
11/03/2019 5397239 126346581 95.90 16991691 74605383 31173758 22.91 70051881 41303925 3337
11/04/2019 22976489 108767331 82.56 17370840 50890159 31590855 23.22 72526262 15737896 2529
11/05/2019 19079866 112663954 85.52 17258883 46844205 31101187 22.86 71308833 12935789 1359
11/06/2019 7406471 124337349 94.38 16629121 57502758 31747371 23.34 78055452 14631643 2993
11/07/2019 10808742 120935078 91.80 18041681 55365441 31891495 23.44 80861355 11922850 1437
11/08/2019 11234165 120509655 91.47 19736141 54308687 31794453 23.37 82677969 11011173 2339
+-------------------------------------------------------------------------------------------------------------------+
Script-3: Bash Script to Get Average CPU & Memory Utilization from SAR Reports
This bash script collects the CPU & memory averages from each data file and displays them on a page.
This bash script is slightly different compared to the above script. It shows the average of both (CPU & Memory) in one location, not the other data.
# nano /usr/src/sar-cpu-mem-avg.sh #!/bin/bash for file in `ls -tr /var/log/sa/sa* | grep -v sar` do sar -f $file | head -n 1 | awk '{print $4}' echo "-----------" sar -u -f $file | awk '/Average:/{printf("CPU Average: %.2f%\n"), 100 - $8}' sar -r -f $file | awk '/Average:/{printf("Memory Average: %.2f%\n"),(($3-$5-$6)/($2+$3)) * 100 }' printf "\n" done
Once you run the script, you will get an output like the one below.
# sh /usr/src/sar-cpu-mem-avg.sh
10/10/2019
———–
CPU Average: 9.33%
Memory Average: 37.98%
10/11/2019
———–
CPU Average: 9.48%
Memory Average: 38.48%
10/12/2019
———–
CPU Average: 10.07%
Memory Average: 36.87%
10/13/2019
———–
CPU Average: 12.05%
Memory Average: 35.93%
10/14/2019
———–
CPU Average: 10.68%
Memory Average: 36.57%
10/15/2019
———–
CPU Average: 10.12%
Memory Average: 37.78%
10/16/2019
———–
CPU Average: 11.44%
Memory Average: 36.92%
10/17/2019
———–
CPU Average: 10.26%
Memory Average: 36.94%
10/18/2019
———–
CPU Average: 9.91%
Memory Average: 37.90%
10/19/2019
———–
CPU Average: 9.56%
Memory Average: 37.83%
10/20/2019
———–
CPU Average: 9.79%
Memory Average: 28.20%
10/21/2019
———–
CPU Average: 9.72%
Memory Average: 36.00%
10/22/2019
———–
CPU Average: 10.43%
Memory Average: 38.18%
10/23/2019
———–
CPU Average: 10.12%
Memory Average: 37.47%
10/24/2019
———–
CPU Average: 9.20%
Memory Average: 37.91%
10/25/2019
———–
CPU Average: 12.98%
Memory Average: 38.91%
10/26/2019
———–
CPU Average: 11.73%
Memory Average: 38.92%
10/27/2019
———–
CPU Average: 11.70%
Memory Average: 39.55%
10/28/2019
———–
CPU Average: 10.20%
Memory Average: 40.22%
10/29/2019
———–
CPU Average: 11.53%
Memory Average: 39.21%
10/30/2019
———–
CPU Average: 11.33%
Memory Average: 37.55%
10/31/2019
———–
CPU Average: 14.61%
Memory Average: 31.34%
11/01/2019
———–
CPU Average: 18.24%
CPU Average: 15.93%
Memory Average: 33.34%
Memory Average: 15.43%
11/02/2019
———–
CPU Average: 13.47%
Memory Average: 35.46%
11/03/2019
———–
CPU Average: 12.49%
Memory Average: 26.38%
11/04/2019
———–
CPU Average: 11.20%
Memory Average: 30.75%
11/05/2019
———–
CPU Average: 11.10%
Memory Average: 36.86%
11/06/2019
———–
CPU Average: 11.62%
Memory Average: 38.11%
11/07/2019
———–
CPU Average: 12.01%
Memory Average: 36.08%
11/08/2019
———–
CPU Average: 10.73%
CPU Average: 14.45%
Memory Average: 35.27%
Memory Average: 15.11%
To make things easier you can just wget the scripts and run them.
Details from this wiki are also located in https://www.2daygeek.com/linux-get-average-cpu-memory-utilization-from-sar-data-report/