Operating System - HP-UX
1827286 Members
2984 Online
109717 Solutions
New Discussion

Re: Get HP Unix System Memory & CPU Usage

 
Dhinakar
Occasional Advisor

Get HP Unix System Memory & CPU Usage

Hi,

I have read the messages posted in this forum regarding various methods to get system memory usage. I tried ps, vmstat, top, sar, glance etc. My requirement is to get the Unix system memory usage & cpu usage through a program (java or c). I am in the process of building a monitoring tool which will get the above details from an unix machine as and when required and store it in a database for future analyses.

In this context I found the code (c program) posted by Brian Bergstrand very useful. But I get compile errors if I try to compile the code in my HP Unix 11i machine. The error is pasted below:-

cc: "memdetail.c", line 29: error 1574: Unknown size for "sbuf".
cc: "memdetail.c", line 30: error 1574: Unknown size for "dbuf".
cc: "memdetail.c", line 31: error 1574: Unknown size for "vbuf".
cc: "memdetail.c", line 40: error 1594: The sizeof operator cannot be applied to types with unknown size.
and so on..............

I think the code needs to be altered to compile in this version of unix. Can someone please provide me the correct program or the binary file. The binary file (memdetail) that I downloaded from this forum gives "Memory fault(coredump)" error.

If there is any other way to get the unix system cpu and mem usage, please let me know. I have attached memdetail.c program for your reference.

Thanks in advance,

Dhinakar


18 REPLIES 18
Steven E. Protter
Exalted Contributor

Re: Get HP Unix System Memory & CPU Usage

Shalom Dhinakar,

I believe you may want to try a gcc compiler on this code.

If its not able to be compiled, then you must either change the code or find another tool.

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
Venkatesh BL
Honored Contributor

Re: Get HP Unix System Memory & CPU Usage

Does your system have the /usr/include/sys/pstat.h file?
Dennis Handly
Acclaimed Contributor

Re: Get HP Unix System Memory & CPU Usage

This compiles fine on both PA and IPF if you take the -Ae default. c89 or -Aa will get those errors.

>SEP: I believe you may want to try a gcc compiler on this code.

The bundled C compiler also compiles it.

>Venkatesh: Does your system have the /usr/include/sys/pstat.h file?

That would give a different error.
Geoff Wild
Honored Contributor

Re: Get HP Unix System Memory & CPU Usage

Strange - I've compiled with the default compiler on 11.11, 11.23, 11.31 on parisc and Itanium with no issues a all with the buillt in HP-UX compiler...

/usr/ccs/bin/cc


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
David Bellamy
Respected Contributor

Re: Get HP Unix System Memory & CPU Usage

I got these same program yesterday and it compiled with no errors on all my HP/UX systems from 11.00 up.
rajdev
Valued Contributor

Re: Get HP Unix System Memory & CPU Usage

Hi ,

please find the compiled binary attached.
parisc version

Regards,
RD
Dhinakar
Occasional Advisor

Re: Get HP Unix System Memory & CPU Usage

Rajdev,

I am getting "Memory Fault(coredump)" if I try to execute your binary. I already got a binary from this forum but since it gave this coredump error I wanted to compile the program on my unix server (HP-UX B.11.11 U 9000/800) and check it out.

Dear Other members,

Thanks for all your reponses.

If I compile with -Ae option, actually nothing happens. I could neither see any binaries being created not I get any error. Please assist me to fix this issue.

Have anyone tried using "Runtime.getRuntime().exec" java function to call some unix utilities like top, glance etc. and get the cpu & memory usage of unix system? If so, please guide with me the code.

I am quite please with the response I am getting from this forum. I hope I will be able to fix my issue soon.

Regards,

Dhinakar
Dennis Handly
Acclaimed Contributor

Re: Get HP Unix System Memory & CPU Usage

>I am getting "Memory Fault(coredump)" if I try to execute your binary.

Works fine for me. Perhaps attaching the corefile may help.

>If I compile with -Ae option, actually nothing happens.

Compile with the following and paste the result:
cc -v -Ae ...
system? If so, please guide with me the code.
Dhinakar
Occasional Advisor

Re: Get HP Unix System Memory & CPU Usage

Dennis Handly,

Thanks for your quick response. Please find attached the output of "cc -v -Ae memdetail.c".

Thanks & Regards,

Dhinakar
Dennis Handly
Acclaimed Contributor

Re: Get HP Unix System Memory & CPU Usage

>Please find attached the output of "cc -v -Ae memdetail.c".

(It would have been better if you just had a text file or pasted into the text.)

Everything is working fine. You get no output because you don't have any errors/warnings.
You just need to execute a.out

>I could neither see any binaries being created

What were you looking for?
Dhinakar
Occasional Advisor

Re: Get HP Unix System Memory & CPU Usage

Dennis,

Sorry for not attaching the text file. Thanks for letting me know that everything is working fine.

a.out is giving the desired output in my case as well. Thanks much.

Actually, I was expecting that a binary file with the name "memdetail" will be created so that I can call it from a java program and get the memory info as and when required. Please let me know how can I create such a binary to be called by a java program.

Thanks & Regards,

Dhinakar
Dennis Handly
Acclaimed Contributor

Re: Get HP Unix System Memory & CPU Usage

>I was expecting that a binary file with the name "memdetail" will be created

I thought this was obvious so I didn't mention it:
$ cc -Ae memdetail.c -o memdetail
http://docs.hp.com/en/10946/options.htm#opt-o
Dhinakar
Occasional Advisor

Re: Get HP Unix System Memory & CPU Usage

Dennis,

Thanks again for your prompt response. I am new to hp environment. I could now successfully create the binary and it works fine. I have assigned 5 points to you in all. Thanks very much.

Regards,

Dhinakar
Dennis Handly
Acclaimed Contributor

Re: Get HP Unix System Memory & CPU Usage

>I have assigned 5 points to you in all.

Have you read "How many points should I assign to replies?":
http://forums1.itrc.hp.com/service/forums/helptips.do?#34

Each reply is eligible for points.
And if you got all our answers you should close the thread.
Dhinakar
Occasional Advisor

Re: Get HP Unix System Memory & CPU Usage

Dennis,

Thanks for pointing me to the points link. Actually my original objective is to get Unix System CPU and Memory usage. I was already checking out SAR and memdetail programs when I posted that message. I used SAR for getting cpu usage and memdetail for getting memory usage. I had an issue with memdetail execution (binary) and compiling (memdetail.c file) which I could fix with your assistance. Hence I assigned 5 points to you.

As a part of the original question, I would also like to know other easier ways to get cpu, mem usage of an unix system through a java program (say using getRuntime().exec() etc.). I feel glance is one of the most accurate tools on hp-ux system with lot of system details. If someone have done this using glance please share the code in this forum.

Thanks & Regards,

Dhinakar
Geoff Wild
Honored Contributor

Re: Get HP Unix System Memory & CPU Usage

I guess this depends on what you are trying to do with this info...

Yet another way to get a ton of info is through the Performance Agent...

I use extract to grab the stats daily from some of my larger environemnts...

I just cut and paste into Excel, tools, text to columns, delimited by |

From root's cron:

# performance
55 23 * * 1-5 /opt/perf/bin/extract -xp -r /home/gwild/zgbltemplate -g -b today 7:00 -e today 18:00 -f stdout | /bin/mailx -s 'IPR performance report' sysadm >/dev/null 2>&1


# cat /home/gwild/zgbltemplate
REPORT "MWA Export on !SYSTEM_ID"
FORMAT ASCII
HEADINGS ON
SEPARATOR="|"
SUMMARY=60
MISSING=0
DATA TYPE GLOBAL
YEAR
DATE
TIME
GBL_CPU_TOTAL_UTIL
GBL_CPU_SYS_MODE_UTIL
GBL_CPU_USER_MODE_UTIL
GBL_CPU_SYSCALL_UTIL
GBL_CPU_INTERRUPT_UTIL
GBL_PRI_QUEUE
GBL_CPU_CSWITCH_UTIL
GBL_SWAP_SPACE_UTIL
GBL_DISK_UTIL_PEAK
GBL_DISK_SUBSYSTEM_QUEUE
GBL_MEM_UTIL
GBL_MEM_CACHE_HIT_PCT
GBL_MEM_PAGEIN_RATE
GBL_MEM_PAGEOUT_RATE
GBL_MEM_SWAPIN_RATE
GBL_MEM_SWAPOUT_RATE
GBL_MEM_QUEUE
GBL_NET_PACKET_RATE
GBL_NET_OUTQUEUE
GBL_NETWORK_SUBSYSTEM_QUEUE


There are plenty of metrics....

https://h10078.www1.hp.com/cda/hpms/display/main/hpms_content.jsp?zn=bto&cp=1-11-15-28^1792_4000_100

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Dhinakar
Occasional Advisor

Re: Get HP Unix System Memory & CPU Usage

Geoff Wild,

Thanks for the details and very sorry for the delay in my reply. I think, now I have enough information. Thanks to one and all who posted valuable information. I will close this topic.

Regards,

Dhinakar
Dhinakar
Occasional Advisor

Re: Get HP Unix System Memory & CPU Usage

$ cc -Ae memdetail.c -o memdetail