I already know how to use grep -w cpu /proc/stat in order to get the cpu stats and identify the user mode. Percentage wise, I just divide it my the total time from the /proc/uptime.

However, how can I get it for the last 24 hours. I know the find -mtime m and I was thinking it could be used since /proc/stat is a folder after all..


There are several ways to get at this information. The first that comes to mind is to use mpstat from a cronjob that would log the info to a file. A command like this would write a summary line after 24 hours.


$ mpstat 86400 1
Linux 3.12.6-200.fc19.x86_64 (greeneggs.bubba.net)  01/22/2014  _x86_64_    (4 CPU)

06:37:16 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
06:37:21 PM  all   20.72    0.00    2.82    2.42    0.35    0.10    0.00    0.00    0.00   73.59
Average:     all   20.72    0.00    2.82    2.42    0.35    0.10    0.00    0.00    0.00   73.59

You can use various switches to mpstat to control exactly what shows up in the output.


With sar you can have this running all the time on your system as a service. It will collect performance data which you can then extract reports from at a later date.

$ sar -f /var/log/sa/sa13 1200 -s 00:00:00 -e 23:59:59

Will produce a report of CPU usage from 12AM (midnight) until 23:59:59 (end of the day) in 20 minute increments (1200 seconds = 20 min.).

This is just an example of the type of output it will produce.

$ sar -u 5 2
Linux 3.12.6-200.fc19.x86_64 (greeneggs.bubba.net)  01/22/2014  _x86_64_    (4 CPU)

06:49:47 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
06:49:52 PM     all     21.44      0.00      3.08      1.16      0.00     74.32
06:49:57 PM     all     21.47      0.00      3.83      3.78      0.00     70.92
Average:        all     21.46      0.00      3.45      2.47      0.00     72.62

You can do a lot more with sar, this is just an example.

  • mpstat is exactly what I'm looking for! I asusme the 1 indicates One day, but what does the first parameter do? (long number) – Atieh Jan 23 '14 at 16:00
  • @Atieh - mpstat will report the average for 86400 (1 days worth of seconds - 60*60*24). The 1 means to report this 1 time. You could have it be longer, say 7, it would report a days avgs. 7 times (1 week). – slm Jan 23 '14 at 16:02
  • yeah I just figured this out from the manual second paragraph from description. Interval in seconds and count is the number of reports! Sweet. Thanks! – Atieh Jan 23 '14 at 16:06
  • btw, is it normal that it takes some time? My system has been 2 days on since booting.. – Atieh Jan 23 '14 at 16:07
  • 1
    omg, I just understood, by the time it ends it shall provide me with the info in the past 24 hours. brilliant... – Atieh Jan 23 '14 at 16:32

It is not readily available.

You could use something like collectd to collect those stats in rrd format for you. Then if graphs are not good enough, rrdxport can help you extract numerical reports.

  • That's also something that sar (from sysstat on Debian) or atop typically log (and you can query the information from them). – Stéphane Chazelas Jan 22 '14 at 9:56
  • Actually, I want everything to be done in bash (built-in). The links you gave me act like API's and I don't want to use them. – Atieh Jan 22 '14 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.