Logging CPU usage over a certain period of time is very easy.
The command below will print 24 lines of CPU statistics, printing a line every 4 seconds.
┌──[jason@192.168.1.2]─[~] └──╼ ╼ $ sar -u 4 24 --human Linux 5.8.0-41-generic (jason-desktop) 12/04/21 _x86_64_ (4 CPU) 09:05:33 CPU %user %nice %system %iowait %steal %idle 09:05:37 all 20.6% 0.0% 8.5% 0.3% 0.0% 70.6% 09:05:41 all 21.4% 0.0% 8.2% 0.0% 0.0% 70.4% 09:05:45 all 24.3% 0.0% 9.6% 0.9% 0.0% 65.1% 09:05:49 all 32.9% 0.0% 8.4% 6.1% 0.0% 52.7% 09:05:53 all 23.1% 0.0% 8.3% 2.7% 0.0% 65.9% 09:05:57 all 22.0% 0.0% 8.4% 0.2% 0.0% 69.4% 09:06:01 all 21.6% 0.0% 7.8% 2.8% 0.0% 67.9% 09:06:05 all 20.6% 0.0% 8.4% 3.6% 0.0% 67.4% 09:06:09 all 21.4% 0.0% 8.7% 0.3% 0.0% 69.6% 09:06:13 all 21.3% 0.0% 7.9% 1.4% 0.0% 69.4% 09:06:17 all 21.1% 0.0% 7.9% 1.9% 0.0% 69.1% 09:06:21 all 20.9% 0.0% 8.8% 1.7% 0.0% 68.5% 09:06:25 all 22.2% 0.0% 7.6% 0.1% 0.0% 70.2% 09:06:29 all 19.6% 0.0% 8.6% 2.5% 0.0% 69.3% 09:06:33 all 19.4% 0.0% 8.8% 1.5% 0.0% 70.4% 09:06:37 all 20.2% 0.0% 8.8% 0.2% 0.0% 70.7% 09:06:41 all 21.0% 0.0% 9.6% 0.6% 0.0% 68.9% 09:06:45 all 20.4% 0.0% 9.0% 3.8% 0.0% 66.9% 09:06:49 all 28.2% 0.0% 10.8% 1.9% 0.0% 59.2% 09:06:53 all 23.0% 0.0% 10.6% 0.0% 0.0% 66.3% 09:06:57 all 21.4% 0.0% 9.2% 0.1% 0.0% 69.3% 09:07:01 all 26.5% 0.0% 9.8% 0.0% 0.0% 63.8% 09:07:05 all 19.6% 0.0% 8.8% 0.3% 0.0% 71.3% 09:07:09 all 20.5% 0.0% 7.4% 0.4% 0.0% 71.8% Average: all 22.2% 0.0% 8.7% 1.4% 0.0% 67.6% |
A nice way to create a set of graphs is with the sargrapher.pl script.
Use this command to generate a sar output file.
┌──[jason@192.168.1.2]─[~] └──╼ ╼ $ sar -u 4 24 -p -A > my.sar |
Then upload it on this website to create a set of very nice graphs.
http://www.fsprings.com/neat/sargrapher.html.
This works very well for getting an idea of the CPU usage over a certain time.