HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to Calculate used memory in KB for monitoring script

 
SOLVED
Go to solution
Mahesh Alexander
Frequent Advisor

Need to Calculate used memory in KB for monitoring script

Good Morning,

We're using a script where we need to extract the exact amount of memory in KB the system is using at that moment.

The closest we've been is with the vmstat command where we can obtain the number of pages used, which are 4KB each, then we multiply this amount and get the total amount of memory used, we think.. We're not quite sure about this as the amount given is sometimes above the total RAM of our Server. Maybe because it does use virtual pages from disc as well?

Is there any other command where we can obtain this information easily?

Commands like glance, top, etc are not useful as we need to obtain the information from a script.

Any idea?

Thanks in advance!
15 REPLIES
Steven E. Protter
Exalted Contributor

Re: Need to Calculate used memory in KB for monitoring script

Shalom,

http://www.hpux.ws/?p=8

That script shows top memory users. It is sorted.

it accepts a command line parameter to tell how many processes to monitor.

So it could be used to get snapshots of all resident memory on the system and do calculations as you desire.

If you take it and modify it, I only ask that you return the results so I can post the modification to the blog.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mahesh Alexander
Frequent Advisor

Re: Need to Calculate used memory in KB for monitoring script

Thanks Steven for you quick response!

Although your response is very useful I am afraid it was not exactly what we are looking for.

The thing is we are using nagios for our servers monitoring. Nagios needs to request the information to our server sporadically and we don't want to run any script on the server itself. Our desire is to execute a command remotely and obtain the total amount of memory used at that moment for that server. We are using now vmstat and think we got the total amount by issuing vmstat and then multiply it by 4 (4KB each page of memory), but we want to know if this is the total amount of RAM and virtual memory used by the system. Are we wrong with this statement?

Thank you!!
James R. Ferguson
Acclaimed Contributor

Re: Need to Calculate used memory in KB for monitoring script

Hi:

Instead of assuming the the pagesize is always 4K (it isn't necessarily) you should query it and use its value as your multiplier:

# getconf PAGE_SIZE

Regards!

...JRF...
Mahesh Alexander
Frequent Advisor

Re: Need to Calculate used memory in KB for monitoring script

Hi James, thanks for the command.

Yes, the result after issuing the getconf command is:

#getconf PAGE_SIZE
4096

So, assuming this we can obtain the exact amount of memory the system is utilizing with the vmstat command. Is there a way to obtain only the RAM Mem usage at a given moment?

Regards,
Steven E. Protter
Exalted Contributor

Re: Need to Calculate used memory in KB for monitoring script

Shalom again,

Page size is 4K

To calculate memory use in kb, divide page figures from vmstat or other page utilities by 4.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ganesan R
Honored Contributor
Solution

Re: Need to Calculate used memory in KB for monitoring script

Hi Mahesh,

vmstat will not show the physical memory usage. It reports the virtual memory usage.

If you want to know the physical memory usage then you may consider the HP tools like "kmeminfo".

kmeminfo will give output like this..


----------------------------------------------------------------------
Physical memory usage summary (in page/byte/percent):


Warning: Bad super pointer deref mem_class_t-->priv_data

Warning: Bad super pointer deref u_mem_class_priv_t-->mrg_file_data
Physical memory = 524288 2.0g 100%
Free memory = 299134 1.1g 57%
User processes = 40564 158.5m 8% details with -user
System = 181778 710.1m 35%

You can grep only the "Free memory"

Hope this helps
Best wishes,

Ganesh.
Mahesh Alexander
Frequent Advisor

Re: Need to Calculate used memory in KB for monitoring script


Hi Ganesan, that is exactly what I want but unfortunately kmeminfo was not found in our systems. We use V11.23. An easy way to get this command to function?? :) We are getting close with this one.

p.s: want to thank you all for your quick support with this thread.
Don Morris_1
Honored Contributor

Re: Need to Calculate used memory in KB for monitoring script

Using kmeminfo for this is like using a UDBC-II connector to check your oil level.

vmstat reports virtual pages, but the free pages is physical. You can use it _if_ you know the total RAM in the first place (there are various tricks to get this such as adb, grepping the syslog for the boot up message, etc.). The best way to get both though is to write you own little pstat based program to report just what you want however you find it most useful for your script.

Attaching a sample -- you'll likely want to just comment out/remove all you're not interested in (I expect the "physical" output is all you want).
Ganesan R
Honored Contributor

Re: Need to Calculate used memory in KB for monitoring script

Hi Mahesh,

kmeminfo in not an internal command. If you have contract you can get it from HP.
Best wishes,

Ganesh.
Suraj K Sankari
Honored Contributor

Re: Need to Calculate used memory in KB for monitoring script

Hi,

Please assign some points who give there valuable time for your problem.

To know how to assign points please go through the below link.


http://forums13.itrc.hp.com/service/forums/helptips.do?#33

Suraj
Mahesh Alexander
Frequent Advisor

Re: Need to Calculate used memory in KB for monitoring script

Hi again

I want to thank you all for your posts.

I found some few commands which offer total and free memory, very handy if you need this information with no kmeminfo available:

TOTAL MEMORY:
# echo phys_mem_pages/2d | adb /stand/vmunix /dev/kmem

FREE MEMORY:
# echo freemem/2d | adb /stand/vmunix /dev/kmem

Regards.
Mahesh Alexander
Frequent Advisor

Re: Need to Calculate used memory in KB for monitoring script

# echo freemem/2d | adb /stand/vmunix /dev/kmem
Don Morris_1
Honored Contributor

Re: Need to Calculate used memory in KB for monitoring script

Just be aware that this is unsupported. No promises are made or implied that kernel global variables can't change between releases or even between patches. (This is why I recommended pstat -- that _is_ a supported interface).
James R. Ferguson
Acclaimed Contributor

Re: Need to Calculate used memory in KB for monitoring script

Hi :

@ Don

well, aside from the unsupported method the OP likes, he also assumes that the size of a page will always be 4K :-)

Regards!

...JRF...
Mahesh Alexander
Frequent Advisor

Re: Need to Calculate used memory in KB for monitoring script

Hi again

@ JRF,
No worries about that as we can whether choose between the supported method or not. And also we assume the final result depending on the size of PAGE_SIZE, so always we'll get the right result ;)