Operating System - HP-UX
1830044 Members
7082 Online
109998 Solutions
New Discussion

Want to Get % used and Total Memory in HP-UX

 
SOLVED
Go to solution
BTO
Regular Advisor

Want to Get % used and Total Memory in HP-UX

Hi Guys,
I am new to HP-UX and I am stuck in a problem here. I want to get total memory and % used Memory from HP-UX. After going through commands I can only get total Memory and free Memory from System, There are two commands One is providing total memory other is providing free Memory. I need to concate these ouput as well as want to generate % used memory using these output.  Please note that I can't create scripts. I just need to use one line command and output should also be in one line.

to get Total Memory I am using:

machinfo | awk '/Memory/ {print $2};'

Its output looks like this>> 32665
to get Free Memory I am using:top -d 1 | grep Memory | awk 'gsub(/K/,"")'| awk '{print $8/1024}'

Its output looks like this>> 22847.8
When I use && operator between these two commands:

top -d 1 | grep Memory | awk 'gsub(/K/,"")'| awk '{print $8/1024}' && machinfo | awk '/Memory/ {print $2};'

I get output like this: Two Different Lines.

22847.7

32665
Now As I have these values. I need to
1. generate % used Memory like ((32665-22847.7)/32665)*100

2. show all these ouput in one line, Like this

3266530%

Looking forward for your response & suggestions. 

Regards,
Kaleem Ullah
10 REPLIES 10
Dennis Handly
Acclaimed Contributor
Solution

Re: Want to Get % used and Total Memory in HP-UX

>Please note that I can't create scripts. I just need to use one line command

 

Any particular reason why?

top -n 1 -d 1 -f top.$$; awk -v total=$(machinfo | awk '/Memory/ {print $2}')  \

 '/Memory/ {gsub(/K/,"") ; print total, (total - $8/1024) * 100/ total "%"}' top.$$ ; rm top.$$

 

BTO
Regular Advisor

Re: Want to Get % used and Total Memory in HP-UX

Thanks Dennis,

 

Actually right Now I am working with HP SiteScope Memory Monitor. Currently Memory Monitor for HP-UX is not showing Physical Memory. So I have to create a set of commands that can easily be run on each HP-UX machine & we don't need to deploy scripts on them. 

 

Thanks Alot for your solution. Problem reolved

 

 

Regards,
Kaleem Ullah
Dennis Handly
Acclaimed Contributor

Re: Want to Get % used and Total Memory in HP-UX

>Thanks A lot for your solution. Problem resolved

 

If you are happy with your answers, please assign kudos.

BTO
Regular Advisor

Re: Want to Get % used and Total Memory in HP-UX

Sorry I forgot to assign Kudos.
Regards,
Kaleem Ullah
Arunabha Banerjee
Valued Contributor

Re: Want to Get % used and Total Memory in HP-UX

When I am running the above command in HP-UX 11.23 version I am getting the following output.

 

$ top -n 1 -d 1 -f top.$$; awk -v total=$(machinfo | awk '/Memory/ {print $2}') \
> '/Memory/ {gsub(/K/,"") ; print total, (total - $8/1024) * 100/ total "%"}' top.$$ ; rm top.$$
= awk: Cannot divide by zero.
 The input line number is 13. The file is top.8530.
 The source line number is 1.
$

 Did I miss anything ?

 

AB
James R. Ferguson
Acclaimed Contributor

Re: Want to Get % used and Total Memory in HP-UX


@Arunabha Banerjee wrote:

When I am running the above command in HP-UX 11.23 version I am getting the following output.

 

$ top -n 1 -d 1 -f top.$$; awk -v total=$(machinfo | awk '/Memory/ {print $2}') \
> '/Memory/ {gsub(/K/,"") ; print total, (total - $8/1024) * 100/ total "%"}' top.$$ ; rm top.$$
= awk: Cannot divide by zero.
 The input line number is 13. The file is top.8530.
 The source line number is 1.
$

 Did I miss anything ?

 


If you are running 11.23 and your server isn't an Itanium one, then 'machinfo' isn't available to return anything.  Hence, the 'total' variable will be interpreted as zero and dividing by zero is a fault.

 

Regards!

 

...JRF...

Dennis Handly
Acclaimed Contributor

Re: Want to Get % used and Total Memory in HP-UX

>When I am running the above command in HP-UX 11.23

 

Yes, I developed it on 11.23 and noticed the machinfo output difference.  Change to:

awk '/Memory/ {print $3}') ...

 

I suppose you could also do:  (I think it was a ":".)

awk '/Memory/ {if ($2 == ":") print $3; else print $2}') ...

Arunabha Banerjee
Valued Contributor

Re: Want to Get % used and Total Memory in HP-UX

Hi James

 

I am running the script on HP-UX 11.23 running on Itanium platform only.

 

$ uname -r; model
B.11.23
ia64 hp server rx6600
$

 

Hi Dennis,

After modifying the script as you suggested I ran again. Please fine below output

 

$ top -n 1 -d 1 -f top.$$; awk -v total=$(machinfo | awk '/Memory/ {print $3}') \
> '/Memory/ {gsub(/K/,"") ; print total, (total - $8/1024) * 100/ total "%"}' top.$$ ; rm top.$$
4066 95.1615%
$

 

The total memory output is okey (4066) but %/used output is not correct (95.1615%).

 

Please find below top output.

 

System: server                                   Sun Aug 14 22:23:55 2011
Load averages: 0.00, 0.00, 0.00
105 processes: 81 sleeping, 24 running
Cpu states:
CPU   LOAD   USER   NICE    SYS   IDLE  BLOCK  SWAIT   INTR   SSYS
 0    0.00   0.2%   0.0%   0.2%  99.6%   0.0%   0.0%   0.0%   0.0%
 1    0.00   0.0%   0.0%   0.0% 100.0%   0.0%   0.0%   0.0%   0.0%
 2    0.00   0.4%   0.0%   0.6%  99.0%   0.0%   0.0%   0.0%   0.0%
 3    0.00   0.0%   0.0%   0.0% 100.0%   0.0%   0.0%   0.0%   0.0%
---   ----  -----  -----  -----  -----  -----  -----  -----  -----
avg   0.00   0.2%   0.0%   0.2%  99.6%   0.0%   0.0%   0.0%   0.0%

Memory: 373332K (290288K) real, 547536K (437264K) virtual, 200184K free  Page# 1/105

 

swapinfo output:

 

$ /usr/sbin/swapinfo -atm
             Mb      Mb      Mb   PCT  START/      Mb
TYPE      AVAIL    USED    FREE  USED   LIMIT RESERVE  PRI  NAME
dev        8192       0    8192    0%       0       -    1  /dev/vg00/lvol2
reserve       -     413    -413
memory     4067    1648    2419   41%
total     12259    2061   10198   17%       -       0    -
$

 

 

AB
Dennis Handly
Acclaimed Contributor

Re: Want to Get % used and Total Memory in HP-UX

>%/used output is not correct (95.1615%).

 

Which do you trust more, top or swapinfo?

(I never use the summary values on top because I don't trust them.  Only the values for each process.)

Note: swapinfo doesn't measure memory, only pseudo swap.

Arunabha Banerjee
Valued Contributor

Re: Want to Get % used and Total Memory in HP-UX

Hi Dennis,

 

Thanks for the explanation now everything is clear to me.

AB