I've been looking at using process accounting for keeping track of various users and sites running scripts that are problematic in our environment instead of trying to do something like scraping top at regular intervals.
The one that isn't particularly clear is which fields really denotes the cpu seconds/minutes used. The manual pages I have read say the 'cpu' column is for seconds burned, however there is alo the 'cp' column displayed with -m - and they can show different totals. For example:
When I use the -m flag, I get
$sa -m | grep username
username 14944 65.53re 29.90cp 5308k
When I use the -u flag and total up the column for 'cpu', I get the following:
sa -u |grep username|awk 'BEGIN{TOTAL=0}{TOTAL=TOTAL+$2}END{print TOTAL}'
1032.86
Can anybody help me understand the difference between the 'cp' and 'cpu' columns in these two different modes?
Thanks!
Let me use an example to help explain what your results above show:
First: I created a bash script that I ran as the user patrickr which was meant to put enough load on the system to be noticeable.
Second: I uninstalled and then reinstalled acct so that my files in /var/log/acct would be fresh. Create a copy of the /var/log/acct/pacct file so that in the future you can easily truncate the file with a properly formatted file (you can't just delete and recreate the file - sa will stop working if you do that). Note that this file is a log of all commands on the system and as far as I can tell there is no way to pull parts on the log based on time periods.
Third: I then ran this script twice as patrickr
I'll give you the results and then I'll explain them:
Ran as root (or any user other that patrickr) After first loop as patrickr:
After second loop as patrickr:
Here's what you're seeing:
sa -m is showing averages for the all the activity for this server overtime. This file grows larger over time as more commands run.
sa -u | grep patrickr is showing the sum of the system and user time in cpu minutes for specific commands.
Running: sa -u |grep patrickr|awk 'BEGIN{TOTAL=0}{TOTAL=TOTAL+$2}END{print TOTAL}'
Will give you a combined total for user patrick but the sa -m command is actually giving you averages. Take a look at the memory values is you need a second example. They're averaged too.
If I add the three results listed above for patrickr, .35 + .37 + .0 and divide by 106 and round to the to the nearest hundredth I'll get 0.01cp.
The result of 0.01cp is the average load of user patrickr on the system in comparison to all load on the system from the time that the acct application was installed (ie since the file /var/log/acct/pacct started keeping track).
A good resource that will help you is at beginlinux.com (original link found here).