https://twitter.com/go_vargo/status/1215281798948642817?s=20
I wasn't familiar with the sar command among the ones introduced in the above Tweet, so I did some research.
sar (System Activity Reporter) is one of the monitoring tools for Linux.
A command that displays statistics such as memory, CPU usage, disk IO, network, and load average, and is included in the sysstat package.
It is possible to display not only real-time stats but also past stats, Since you can see the information retroactively, it is useful for investigating the cause when dealing with a failure.
The type of statistics to display is optionally specified.
sar [...options]
In [... options], specify which resource information to display.
If no option is specified, the resource information for the current day will be acquired. The default information acquisition interval is 10 minutes.
With Amazon Linux 2, past data will be saved under / var / log / sa.
[ec2-user@xxx ~]$ ls -la  /var/log/sa
Total 2652
drwxr-xr-x 2 root root 167 May 24 05:14 .
drwxr-xr-x 8 root root 4096 May 24 05:14 ..
-rw-r--r--1 root root 91760 October 12 2019 sa12
-rw-r--r--1 root root 336992 October 13 2019 sa13
-rw-r--r--1 root root 336992 October 14 2019 sa14
-rw-r--r--1 root root 238880 October 15 2019 sa15
-rw-r--r--1 root root 290320 October 17 2019 sa17
-rw-r--r--1 root root 336992 October 18 2019 sa18
-rw-r--r--1 root root 16960 October 19 2019 sa19
-rw-r--r--1 root root 5328 May 24 05:30 sa24
-rw-r--r--1 root root 68488 October 12 2019 sar12
-rw-r--r--1 root root 249044 October 13 2019 sar13
-rw-r--r--1 root root 249044 October 14 2019 sar14
-rw-r--r--1 root root 214675 October 17 2019 sar17
-rw-r--r--1 root root 249044 October 18 2019 sar18
The number after sar ** indicates the last few days.
The file itself is stored in binary, You can view the contents of the file via sar.
[ec2-user@xxx ~]$ sar -r -f /var/log/sa/sa12
Linux 4.14.123-111.109.amzn2.x86_64 (localhost)October 12, 2019_x86_64_	(1 CPU)
17:23:29 LINUX RESTART
17:30:01 kbmemfree kbmemused%memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
17:40:01 493536 513796 51.01      2088    390136    593996     58.97    166828    253464       252
17:50:01 493540 513792 51.01      2088    390300    593996     58.97    166892    253532       252
18:00:01 493004 514328 51.06      2088    390636    593988     58.97    167000    253844       216
After the command, you can limit the data displayed in real time with [Acquisition interval] [Acquisition count].
If you want to learn the information 3 times every 1 second, follow the steps below.
[ec2-user@xxx ~]$ sar -r 1 3
Linux 4.14.146-119.123.amzn2.x86_64 May 24, 2020_x86_64_	(1 CPU)
05:37:41 kbmemfree kbmemused%memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
05:37:42 585824 421468 41.84      2088    323892    531260     52.74    154588    198628       128
05:37:43 584948 422344 41.93      2088    323892    531260     52.74    155608    198628       128
05:37:44 584568 422724 41.97      2088    323892    531260     52.74    155884    198628       128
Average value:     585113    422179     41.91      2088    323892    531260     52.74    155360    198628       128
##Saves real-time memory information in a file called mem three times at 1-second intervals
[ec2-user@xxx ~]$ sar -r 1 3 -o mem
##View statistics saved in mem file
[ec2-user@xxx ~]$ sar -r -f mem
You can specify the resources to be displayed by changing the options.
--CPU usage
[ec2-user@xxx ~]$ sar -P ALL 1
Linux 4.14.146-119.123.amzn2.x86_64 May 24, 2020_x86_64_	(1 CPU)
05:39:43 CPU%user     %nice   %system   %iowait    %steal     %idle
05:39:44 all 0.00      0.00      0.00      0.00      0.00    100.00
05:39:44 0 0.00      0.00      0.00      0.00      0.00    100.00
--Memory usage
[ec2-user@xxx ~]$ sar -r 1
Linux 4.14.146-119.123.amzn2.x86_64 May 24, 2020_x86_64_	(1 CPU)
05:41:24 kbmemfree kbmemused%memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
05:41:25 586180 421112 41.81      2088    323940    526944     52.31    154808    198444         0
05:41:26 586180 421112 41.81      2088    323940    526944     52.31    154808    198444         0
05:41:27 586180 421112 41.81      2088    323940    526944     52.31    154808    198444         0
--Network
Receive/Number of packets sent
[ec2-user@xxx ~]$ sar -n DEV 1
Linux 4.14.146-119.123.amzn2.x86_64 (ip-172-31-63-105.ap-northeast-1.compute.internal)May 24, 2020_x86_64_	(1 CPU)
05:42:33 IFACE rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
05:42:34 eth0 2.00      0.00      0.10      0.00      0.00      0.00      0.00
05:42:34 lo 0.00      0.00      0.00      0.00      0.00      0.00      0.00
05:42:34 IFACE rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
05:42:35 eth0 1.01      1.01      0.05      0.39      0.00      0.00      0.00
05:42:35 lo 0.00      0.00      0.00      0.00      0.00      0.00      0.00
        Recommended Posts