Simple Linux Process Accouting

# Filed on Oct 28, 2005 by Anthony DiSante reply

Who knew it was so easy?  After Dreamhost recently started dumping some system-profiling logs into my home directory, in order to show me how many CPU minutes my processes were using per day, I realized that I’d like to be able to do this myself on my other servers.  It turns out that it’s really easy to do.

A little googling brought me to the sa(8) man page.  After reading about sa and its friends in the "See Also" section of the manual, I understood what to do.

First you need to install the GNU Accounting Utils, probably from a package named acct.  On Debian for example, I just did "aptitude install acct"; on Gentoo, "emerge -vabk acct" did the trick.  This installed the accton and sa programs (among others) on my system.

Now we’re ready to go.  Run "accton /var/log/acct" and it will log all the processes that run on the system from now on.  (Yes, the log grows pretty quickly, so watch it.  Run "accton" with no arguments to stop logging.)

The accton command produces a binary logfile to help keep the size down, and the sa command reads this binary file to produce human-readable output.  We’ll run "sa -u /var/log/acct" to produce a list of all the processes that have run, along with the amount of CPU time they consumed.

Finally, the good part: the handy sa-analysis.pl script reads the huge list produced by sa, and then displays a nice short list of each process that has run, along with its cumulative CPU usage.  Save the script as /usr/local/bin/sa-analysis and chmod it a+x, then run this command:

sa -u /var/log/acct >/var/log/acctlist && sa-analysis /var/log/acctlist

You should see a nice table like this:

Process         CPU seconds      user   machine   count  average
foo.cgi            395.7600   32.272%    1.649%     511    0.774
random.cgi         327.3200   26.691%    1.364%    2052    0.160
mysqld             145.8200   11.891%    0.608%     231    0.631
someother.cgi      115.9300    9.453%    0.483%     333    0.348
foodb.cgi           80.7400    6.584%    0.336%     231    0.350
iamwinning.cgi      61.3500    5.003%    0.256%     270    0.227
courierpop3d        14.7000    1.199%    0.061%      32    0.459
httpd               11.7800    0.961%    0.049%      95    0.124
rdjpgcom            11.6000    0.946%    0.048%     500    0.023
mrtg                 9.8600    0.804%    0.041%       8    1.233
[...]
accton               0.0000    0.000%    0.000%       1    0.000
locale               0.0000    0.000%    0.000%       2    0.000
less                 0.0000    0.000%    0.000%       1    0.000
mv                   0.0000    0.000%    0.000%       1    0.000
qmail-local          0.0000    0.000%    0.000%       5    0.000
sh                   0.0000    0.000%    0.000%       2    0.000
----------------------------------------------------------------
Total:            1318.8300  100.000%    5.495%    7325
Average per day:  1318.8300    1 days
CPU percentage assumes 24000 cpu seconds per day total.

And presto!  You now know which processes on your system are eating all your CPU time.  Of course, the GNU Accounting Utils are very flexible and can produce many other kinds of reports, so dig into the man pages to find out more.

Reply to this message here:

Your name
Email (why?)
Website (if you have one)
Subject
search posts:

home | archives ]

Shopping Cart

Your cart is empty.

Client Quotes

The work, the thought and the organization you put into this app is incredible.
– Bruce C.
I looked all over trying to find a simple cgi script.  I found that FileChucker was by far the best.  If you have issues with your hosting service's php.ini max upload size then this is the way to go.  Looking forward to future enhancements.
– Bob C.
Nice script, it's saving the day on our project.
– Aaron W.
I just wanted to say that yours is the first product that I've tested so far that hasn't failed on handling uploads.  This is going to work for a print company, so they are handling nothing but large files and all the other solutions I've tried so far have not been reliable.  So far yours has been 100% successful in my tests.
– Kevin H.
I just installed the demo of your product and got it up and running in no time.  I searched high and low for a decent login script and thank God I found yours.
– Adrian F.
FileChucker is working great...  Clients love it.  Vendors love it.  We love it.
– Gerry W.
The amount of customization in the program is incredible.  I was able to integrate it into my existing page layout relatively simply.  I was also able to easily customize the look/feel to match the current site.
– Jason M.
Do you know how rare it is to have a "canned" shopping cart with the ability to fairly easily do complex pricing options on a single item?  Maybe you do, but if you don't... basically, they don't exist!  I have looked.  Everywhere!  And the few that might even come close to the functionality that you have in CornerStore cost a fortune!
– Tashina P.
Just one word: Fantastic.  10-minute job to plug FileChucker into my app, and it now works a treat.  It's through the hard work by people like yourselves that make my job so much easier.  Congratulations on an outstanding product... Many many thanks.
– Sean F.
Our members think your software is fantastic...  I would recommend your software and your company to anyone.  Thanks for all your help.  It has been a pleasure dealing with you.
– Tommy A.
FileChucker is helping drive the backend of several high profile entertainment sites for people like Shania Twain and Dolly Parton.  We're also using it to drive backend file uploads for a multi-billion dollar banking institution.  It's a great product.  We've tried other "chucking" upload solutions with progress bars using flash and php, but nothing works as reliably as FileChucker.
– Michael W.
Thanks again for a great product and great support - beyond expectations.
– Greg S.
FileChucker is a great drop-in solution for file uploads, and worth every penny of its very reasonable cost.  Encodable's support is excellent to boot.
– Loren A.
I just want to say you guys really stand alone in that you have a quality product and you provide genuine customer service.  It's sad but those qualities are seldom found separately, much less together.  Thanks again for your time and help.
– Alex S.
Thank you VERY much for all of your help.  You've really impressed me.  We have support agreements for other software that costs thousands of dollars / year (just for the support), and most of them aren't as helpful as you have been.
– Keith Y.