How to measure CPU/Memory usage?

Posted on 2008-10-07
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?
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Accepted Solution

tjilp earned 55 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 :
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 80 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"
        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 40 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 80 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
LVL 62

Expert Comment

ID: 23217559

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 155
Expand to include initial dialog with two choices. 9 77
iSeries DB2 Query 2 95
Making an alias 7 93
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now