Reputation: 324600
I can get how long the server has been running through uptime
, but is there any way to get the total amount of processor time spent on all processes combined?
I can do this on my Windows desktop by subtracting the System Idle Process time from the uptime, but is there any similar method in Linux?
Upvotes: 3
Views: 433
Reputation: 801
Look into the /proc/stat file. It should contain the idle CPU numbers you're looking for, so with a little math you'll be able to calculate how long the CPU has been idle.
EDIT: Also, here's an example of how to get the percentage from any Linux terminal:
head -n 1 /proc/stat | awk '{ print "\n"; printf (($2+$3+$4+$7+$8+$9)/($2+$3+$4+$5+$6+$7+$8+$9))*100; print "% of the time since the computer was booted has been spent doing work." }'
I think I've got it handling all of the columns correctly there.
Upvotes: 2