Operating System - HP-UX
1819694 Members
3366 Online
109605 Solutions
New Discussion юеВ

Easy command line way to check memory usage

 
SOLVED
Go to solution
Jeanine Kone
Trusted Contributor

Easy command line way to check memory usage

I am looking for the command line way to check memory usage (i.e. how much is used and how much is free).

I know that I can see this in Glance, but I want the actual command so that I can put in ina script and run it from cron once per hour for a few weeks.

I have looked at sar, but it does not seem to have real memery usage info, just swap space and paging. I look at pstat also, but it seems way to complex for my needs.

Any simple, one line solutions???

Thanks, Jeanine

13 REPLIES 13
Sanjay_6
Honored Contributor

Re: Easy command line way to check memory usage

Hi Jeanine,

Try,

vmstat -n 1 10

top
Check out RSS. This is the Real memory (resident set) size of the process, in 1024 byte units.

Hope this helps.

Regards




Sanjay_6
Honored Contributor

Re: Easy command line way to check memory usage

Hi Jeanine,

You can also try,

UNIX95= ps -e -o "user,vsz,pid,ppid,args"

here vsz -> Size in KB of the core image of the process.

you can sort the above output too,

UNIX95= ps -e -o "user,vsz,pid,ppid,args" |sort -rkn2 |more

Hope this helps.

Regds

S.K. Chan
Honored Contributor

Re: Easy command line way to check memory usage

You can also use this method to capture the glance screen (just the memory report screen)..

# glance -m -j 5 -iterations 2 -f /tmp/output > /dev/null

-m = just memory screen
-j 5 = ev 5 sec
-iterations 2 = # iterations
-f /tmp/output = output to file /tmp/output

Direct all to null so that it does not show up in std output.
hpuxrox
Respected Contributor

Re: Easy command line way to check memory usage


Hello,

I like to use

top -h -d 1

and look at Memory from there.


Thanks,

-Yates
hari jayaram_1
Frequent Advisor

Re: Easy command line way to check memory usage

Hi,

As Sanjay suggested vmstat is fine. However if you have meassureware and perf view installed please let me know and I can suggest a method where you do not need to have a cron job and get the data.

Thanks

Regards

Hari
A. Clay Stephenson
Acclaimed Contributor

Re: Easy command line way to check memory usage

Hi:

Since you have Glance, let's use the mwaget command-line interface.

I assume that /opt/perf/bin is in your PATH.

e.g.
mwaget -metric "SCOPE:(GLOBAL):GBL_MEM_UTIL"
(Percentage global memory utilization during the sampling interval.)

mwaget -metric "SCOPE:(GLOBAL):GBL_MEM_FREE_UTIL"
(Percentage global memory free during the sampling interval.)


If it ain't broke, I can fix that.
Mladen Despic
Honored Contributor
Solution

Re: Easy command line way to check memory usage

If you save the following to a file in your current directory (let's call it mem.syntax):

PRINT "System Memory: ", gbl_mem_sys
PRINT "Buffer Cache: ", gbl_mem_cache
PRINT "User Memory: ", gbl_mem_user
PRINT "Free Memory: ", gbl_mem_free
PRINT "-------------------------------"
PRINT "Total Physical Memory: ", gbl_mem_phys

then you can get a nice memory usage summary by running:

glance -adviser_only -syntax mem.syntax -j 1 -iterations 2 2>/dev/null | tail -6

The metrics listed above (gbl_mem_xxxx) can also be used with Clay's suggestion.

Other Measureware and Glance metrics are listed in
/opt/perf/paperdocs/mwa/C/metrics.txt

and

/opt/perf/paperdocs/gp/C/metrics.txt
Mladen Despic
Honored Contributor

Re: Easy command line way to check memory usage

Jeanine,

You can also use Glance in "adviser only" mode to log any performance metrics every hour for 7 days.

For example, with the same mem.syntax file in your current directory, run:

nohup glance -adviser_only -syntax mem.syntax -j 3600 -iterations 168 -f glance.out &

In this case I would also include the timestamp header in mem.syntax:

PRINT " ", gbl_statdate, " ", gbl_stattime
PRINT "------------------------------------------------------------------------------------
MANOJ SRIVASTAVA
Honored Contributor

Re: Easy command line way to check memory usage

Hi Jeanine


If you want something like this :
Memory Stat total used avail %used
physical 32764.0 24296.4 8467.6 74%
active virtual 16899.8 10480.4 6419.4 62%
active real 18039.3 10747.2 7292.1 60%
memory swap 26522.5 19504.4 7018.1 74%
device swap 3332.0 3332.0 0.0 100%

you may like to compile a simple c program attached whihc i got from these forums too . Just do a cc filename and you will get a exe which can be run from the command line.


Manoj Srivastava
Jeanine Kone
Trusted Contributor

Re: Easy command line way to check memory usage

Thanks everybody for the responses - I am going to try them out today and then assign your points. I got a lot of good answers!!

Jeanine
Dinesh Ramaswamy
New Member

Re: Easy command line way to check memory usage

Hi Jeanine,
Please try this one-liner...
grep Physical /var/adm/syslog/syslog.log

All the best...
Regards,
Dinesh Ramaswamy
harry d brown jr
Honored Contributor

Re: Easy command line way to check memory usage

You want to take a complex issue (memory usage in unix) and reduce it to a "simple" one line command?

answer: write yourself a program/script that will output such.

live free or die
harry
Live Free or Die
Jeanine Kone
Trusted Contributor

Re: Easy command line way to check memory usage

Ok guys, this question was asked and answered back in may - please no more responses!