Operating System - HP-UX
1752681 Members
5680 Online
108789 Solutions
New Discussion юеВ

Re: How to get CPU speeds and RAM without cstm or root

 
nancy rippey
Trusted Contributor

How to get CPU speeds and RAM without cstm or root

I've see posts asking similar questions, I figured I'd share. I found one similar post and that got me going. I used inline perl.

I wrote code to collect inventory across our enterprise, at some point I'll post the inventory source for AIX, Solaris, Linux, and HP-UX, likely to sourceforge. I can get 3+ machines a minute without any agent code, well other than SSH. I prefer to work without privilege when possible, thus I needed a solution. I have worked towards threading my code so I can collect across 300 machines in under 5 mintes. I am collectiong performance information, kernel parameters, software packages, patches, LVM, filesystems, ..etc.

We've seen cstm hang, and frankly it takes too long when it works right.

I got tired of trying to work around the issue, this works on 11.00, 11.11, and 11.22.

Please note on IA64 you'll have to use the perl out of /opt/perl_64/bin, on PARISC it seems you can use the 32 bit perl.

for RAM:

perl -e 'local($PSTAT,$PSTAT_STATIC,$mem_info,$PSTAT_STRUCT)=(239,2,"\0"x120,"LI4L");
syscall($PSTAT,$PSTAT_STATIC,$mem_info,length($mem_info),1,0);
print "RAM=".int((unpack($PSTAT_STRUCT,$mem_info))[4]*((unpack($PSTAT_STRUCT,$mem_info))[5])/(1024*1024))."\n";'

for CPU speeds:

perl -e 'local($PSTAT, $PSTAT_PROCESSOR)=(239,10);
local($struct_pst_processor)=("L30");
local($cpu_info, $cpu_ticks);
$cpu_info = "\0" x 120;
syscall($PSTAT, $PSTAT_PROCESSOR, $cpu_info, length($cpu_info), 1, 0);
($cpu_ticks)=(unpack($struct_pst_processor, $cpu_info))[26];
print "speed=".int($cpu_ticks/10000)."\n";'

Tom Ferony - Union Pacific Railroad tomferony@up.com

 

 

P.S.This thread has been moved from HP-UX>System Administration to HP-UX > languages- HP Forums Moderator

nrip
6 REPLIES 6
Pete Randall
Outstanding Contributor

Re: How to get CPU speeds and RAM without cstm or root

Tom/Nancy,

Very helpful. I've bookmarked this for future reference. Thanks.


Pete

Pete
H.Merijn Brand (procura
Honored Contributor

Re: How to get CPU speeds and RAM without cstm or root

I'll look at your stuff more closely. Meanwhile I invite you to look at my script (also - of course - in perl) that knows about HP-UX (10.20, 11.00, 11.11, and 11.23), AIX (4.3 and 5.2 tested), and linux (SuSE, but probably all)

It takes into account that you might not be root, and leaves out what it cannot fetch

From http://mirrors.develooper.com/hpux/faq.html
http://mirrors.develooper.com/hpux/ux

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
harry d brown jr
Honored Contributor

Re: How to get CPU speeds and RAM without cstm or root


Quite cool, but I have 2560 MB's of ram and your script returned 2550 MB - Not a big deal. The CPU speed hit the nail on the head!


thanks

live free or die
harry d brown jr
Live Free or Die
Alex Lavrov.
Honored Contributor

Re: How to get CPU speeds and RAM without cstm or root

Hey, thanx for the code.

I'm using this great script:
http://www.cfg2html.com/
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Geoff Wild
Honored Contributor

Re: How to get CPU speeds and RAM without cstm or root

Nicely done - but I too use cfg2html as well as sysinfo301 from hp.

As far as memory goes, the attached c program runs a lot quicker then yuor perl script - and doesn't need root.

Output like:

$ /usr/local/bin/memdetail

Memory Stat total used avail %used
physical 10080.0 8445.1 1634.9 84%
active virtual 7313.6 1179.7 6133.9 16%
active real 5818.8 569.8 5248.9 10%
memory swap 7707.8 1715.5 5992.2 22%
device swap 28080.0 6852.3 21227.7 24%


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.
nancy rippey
Trusted Contributor

Re: How to get CPU speeds and RAM without cstm or root

I guess I should explain what I'm doing.

Inventory - I'm not distributing any code at all to any box on five different UNIX platforms (Zero Code Deployment), all I have is secure shell access via keys. The data is stored in a database to allow for cross referencing, comparisions, change history, graphing of sar data, ..etc. I'll try to attach a little sample of the "output".

Connectivity - I even have the ability to connect via SSH, and X-windows without code deployment to the client, all in a browser. The Xwindows stuff is slight of hand with perl acting like a one time inetd (to customize resolution and color depth), Xvnc using xdmcp, Xvnc applet, and javascript (to open a new window and get color depth and resolution). For SSH I'm using mindterm, which allows for copying of files etc.

Recovery - Upon the same framework I have built a failover/disaster recovery system that allows us to recover 300GB databases to off site boxes in less than 10 minutes. No volume groups defined on the target at all, but I do have full audits if PVIDs are on disks on the remote boxes. Here I have to deploy a little code, a tiny program called sudo to escalate my privileges.

I feel that this approach scales much better.
I have permission to post all of my code I just need to clean it up, well and get the time. ;)

Tom Ferony - Union Pacific Railroad
tomferony@up.com
nrip