Learn how to a build a cloud-first strategyRegister Now


How to measure CPU/Memory usage?

Posted on 2008-10-07
Medium Priority
Last Modified: 2013-12-26

I'm working on a project that one of its tasks is to measure the average memory and cpu usage for the passed X minutes. The plan is to cover tier 1 Unix/Linux OS,

I'm a programmer and not very familiar with the different technical aspects of cpu and memory but I do know that these is no single number that represents them.
I found out in Unix the command "vmstat" that gives information about memory, cpu, page fault and other system parameters but I'm not sure this is the right tool. I mean, there is user cpu usage and system cpu usage. How do you figure out a single number that represents the overall cpu usage? The same goes for memory, there is phisical memory, and virtual memory and some other memory related parameters.
And what happen if you have 16 cpus? Can you boil it down to a single number?

The design is that a user will define a minimum free cpu usage and a minimum available memory, and if these conditions are met, only then other tasks will be performed. This is to prevent a situation in which a task is submitted to a machine that is already overloaded.

How would you approach such a task?
Do you know of any 3rd parties softwares or utilities that yield such information?

Question by:nivo_Z
  • 3
  • 2
  • 2
  • +2
LVL 45

Expert Comment

ID: 22657456
Use top command for real time monitoring ... top -b gives you periodic snapshots ... man top for more info
Also look into time command to time the execution of your program ... and of course there are profilers for memory and CPU e.g. memprof, valgind, gprof etc.

Author Comment

ID: 22657908
Thanks fpr your reply.
Top is not necessarily installed, the solution should be generic and sould use tools that exist by default.
LVL 45

Expert Comment

ID: 22657941
what all tools are available?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

tjilp earned 110 total points
ID: 22658009
How about something simple like "ps".
ps has an option  that allows you to format it's output.
online man page example : http://www.netadmintools.com/html/1ps.man.html
or better try : man ps

for instance "ps -eo pid,pcpu,comm,args" gives you the pid , the processor usage, process name and it´s arguments

LVL 62

Expert Comment

ID: 22695344
SNMP agent is existent on all platforms. read host mib.

Assisted Solution

deloptes earned 160 total points
ID: 23212029
how to mesure the memory usage of a perl script?

this can not be caught with top, ps and /usr/bin/time -v prints everywhere a 0.

time prints
real    0m0.608s
user    0m0.523s
sys     0m0.033s

/usr/bin/time -v
        Command being timed: "perl app.pl"
        User time (seconds): 0.51
        System time (seconds): 0.03
        Percent of CPU this job got: 81%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.66
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 3764
        Voluntary context switches: 147
        Involuntary context switches: 180
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

LVL 62

Assisted Solution

gheist earned 80 total points
ID: 23212123
You should use process accounting. most likely psacct package contains sa, sar and accton tools and google will show you enough guidance for your purpose.

Assisted Solution

deloptes earned 160 total points
ID: 23216229
Hello, thank zou for the answer. I was googleing for about an hour but couldnät find anzthing usable, also non of the mentioned programs has ever appeared upto page #5 in google :-) so I sould try something you've mentioned google about it and read the man page

thanks and regards

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question