System resource information on HP-UX
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > System resource information on HP-UX




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    System resource information on HP-UX  
k.szczesny@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-15-06 06:21 PM

Hi,

i'm new to HP-UX, but i have to write a library, from which i will get
info such as:
cpu kernel time
cpu user time
cpu idle time
(average to all processors)
free ram
used ram
total ram

to pass it to Java application trough JNI.
I already wrote such library for windows, but now i need one for HP-UX
(ver. B.11.11 9000/800).
I''ve tried with systeminfo, but i can't get it to work. I've been
trying several code samples found across the google, but i guess all of
them were made for other systems then hp-ux.

Here's a quick sample:

#include <stdlib.h>
#include <stdio.h>
#include <sys/sysinfo.h>

int main(int argc, const  char *argv[])
{
struct minfo s_info;
int ret = sysinfo(s_info);

if(ret == -1){
perror("");
exit(-1);
}
return 1;
}

Probably it's lame, but i really have to solve this. Information passed
by this library is crucial for me :/
Please, help ;)

Best regards,
Krystian






[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
moi


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-15-06 06:21 PM

On Wed, 15 Nov 2006 06:21:12 -0800, k.szczesny wrote:


>   struct minfo s_info;
>   int ret = sysinfo(s_info);
>

You'll at least need an & here.

Sysinfo is a linux-extension. Maybe you should try getrusage()
getrlimit(), and friends.

HTH,
AvK





[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
Rick Jones


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-16-06 12:28 AM

moi <root@localhost.localdomain> wrote:
> On Wed, 15 Nov 2006 06:21:12 -0800, k.szczesny wrote: 
[vbcol=seagreen]
> You'll at least need an & here.

> Sysinfo is a linux-extension. Maybe you should try getrusage()
> getrlimit(), and friends.

Better still (?), peruse the manpage for pstat and start from there 

rick jones
--
web2.0 n, the dot.com reunion tour...
these opinions are mine, all mine; HP might not want them anyway... 
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...





[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
k.szczesny@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-16-06 06:30 AM

moi wrote:
> On Wed, 15 Nov 2006 06:21:12 -0800, k.szczesny wrote:
>
> 
>
> You'll at least need an & here.
>
> Sysinfo is a linux-extension. Maybe you should try getrusage()
> getrlimit(), and friends.
>
> HTH,
> AvK

Hi,

thank You for reply.
Unfortunately getrusage and getrlimit gives information about usage of
a certain process. I need info about whole system.






[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
k.szczesny@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-16-06 12:29 PM


Rick Jones wrote:
> moi <root@localhost.localdomain> wrote: 
> 
> 
>
> Better still (?), peruse the manpage for pstat and start from there 
>
> rick jones

Thanks for reply,

it helped a lot, now i've got information about cpu usage, all i have
left to do is get info about RAM. in pstat there are information about
virtual memory only as i can see.
If You could point me into right direction i would be gratefull.

Best regards,
Krystian

P.s.

It's not that i like to anwer my own questions, but i hate to search in
groups for a solution, find a question and an answer that somebody did
his job, but gave no solution to public ;]

Here is how i did it:

#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/unistd.h>
#include <stdio.h>
#include <string.h>
#define MAX_PROCS 128
#define VALID_CPUSTATES 9

/*
//
// Processor states on HP-UX
// 0 - CPU_USER
// 1 - CPU_NICE
// 2 - CPU_SYSTEM
// 3 - CPU_IDLE
// 4 - CPU_WAIT
// 5 - CPU_BLOCK
// 6 - CPU_SWAIT
// 7 - CPU_INTERRUP
// 8 - CPU_KERNEL
/*
struct pst_processor pstat_buffer[MAX_PROCS];
struct pstat_dyn;

int rc;
int i, j, total_prev;
int tot_prev[VALID_CPUSTATES], tot_cur[VALID_CPUSTATES],
tot_delta[VALID_CPUSTATES];

main()
{

 rc=pstat_getprocessor(pstat_buffer,sizeo
f(struct pst_processor),
pstat_dyn.psd_proc_cnt, 0);

if ( rc == -1 )
return rc;


for (i=0;i<VALID_CPUSTATES;i++)
{
tot_prev[i]=pstat_dyn.psd_cpu_time[i];
}

sleep(200);

rc=pstat_getdynamic(&pstat_dyn,sizeof(struct pst_dynamic), 1,0);

if ( rc == -1 )
return rc;

for (i=0;i<VALID_CPUSTATES;i++)
{
tot_cur[i]=pstat_dyn.psd_cpu_time[i];
tot_delta[i] = tot_cur[i] - tot_prev[i];
}

}

// and now with tot_delta one can measure the percentage of use by
certain type of work cpu does






[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
Rick Jones


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-16-06 06:17 PM

k.szczesny@gmail.com wrote:
> Rick Jones wrote: 
[vbcol=seagreen]
> Thanks for reply,

> it helped a lot, now i've got information about cpu usage, all i have
> left to do is get info about RAM. in pstat there are information about
> virtual memory only as i can see.
> If You could point me into right direction i would be gratefull.

Perhaps some of the "pstat_static" stuff will talk about RAM.  Perusal
of the pstat include file(s) might find it.  Otherwise, at the risk of
it doing "something else" you could try the latest PD top sources
and/or a tusc (aka system call) trace of top running on an HP-UX
system (or of vmstat or other tools I suppose...)

rick jones
--
a wide gulf separates "what if" from "if only"
these opinions are mine, all mine; HP might not want them anyway... 
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...





[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
Don Morris


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-17-06 12:20 AM

Rick Jones wrote:
> k.szczesny@gmail.com wrote: 
> 
> 
>
> Perhaps some of the "pstat_static" stuff will talk about RAM.  Perusal
> of the pstat include file(s) might find it.  Otherwise, at the risk of
> it doing "something else" you could try the latest PD top sources
> and/or a tusc (aka system call) trace of top running on an HP-UX
> system (or of vmstat or other tools I suppose...)

Yeah -- I tried to point him at pstat() in comp.lang.c, but I guess that
didn't get read.

[Rick, this is directed at k.szczesny -- not at you.. ;) ]
What you want is some combination of pstat_getvminfo(),
pstat_getstatic() and pstat_getdynamic(). Exactly what usage depends
on exactly what you want... read "man 2 pstat" to find out where the
headers live, and check the fields and their descriptions for the
structures filled in by those.

If all you want is total RAM on the machine, and total RAM in
use [by kernel + user + firmware + bad pages, etc.],
physical_memory is in the pst_static structure [total RAM],
and psd_free in the pst_dynamic structure is your free RAM -
both should be in pages, I believe. Per-process RAM usage,
virtual memory consumption, swap and the like will take more
fields/calls.

More arcane machine-dependent things such as CPU types, hardware
bits and the like are best found via the sysconf interface.
"man 2 sysconf"

Take a look -- and feel free to follow up if you have specific
questions.

Don





[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
Krystian


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-17-06 12:30 PM


Don Morris wrote:
> Rick Jones wrote: 
>
> Yeah -- I tried to point him at pstat() in comp.lang.c, but I guess that
> didn't get read.
>
> [Rick, this is directed at k.szczesny -- not at you.. ;) ]
> What you want is some combination of pstat_getvminfo(),
> pstat_getstatic() and pstat_getdynamic(). Exactly what usage depends
> on exactly what you want... read "man 2 pstat" to find out where the
> headers live, and check the fields and their descriptions for the
> structures filled in by those.
>
> If all you want is total RAM on the machine, and total RAM in
> use [by kernel + user + firmware + bad pages, etc.],
> physical_memory is in the pst_static structure [total RAM],
> and psd_free in the pst_dynamic structure is your free RAM -
> both should be in pages, I believe. Per-process RAM usage,
> virtual memory consumption, swap and the like will take more
> fields/calls.
>
> More arcane machine-dependent things such as CPU types, hardware
> bits and the like are best found via the sysconf interface.
> "man 2 sysconf"
>
> Take a look -- and feel free to follow up if you have specific
> questions.
>
> Don

Thank You Don,

that helped a lot.

My library is done, all i have to do is make it work with java.
On windows there was no problem, but on hp-ux it just can't see the
library, though it's in a directory defined in java.library.path.

Best regards to all,
thank You for help,

Krystian






[ Post a follow-up to this message ]



    Re: System resource information on HP-UX  
Krystian


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-17-06 12:30 PM


Krystian wrote:
> Don Morris wrote: 
>
> Thank You Don,
>
> that helped a lot.
>
> My library is done, all i have to do is make it work with java.
> On windows there was no problem, but on hp-ux it just can't see the
> library, though it's in a directory defined in java.library.path.
>
> Best regards to all,
> thank You for help,
>
> Krystian

It's solved!
Thanks to Gordon Beaton from comp.lang.java.programmer.
He did same example file as I did, and run it with strace /i can't/.
java searches for lib+filename_from_application+.sl file, so i had to
rename my uxinfo.sl to libuxinfo.sl and now it works - well... at least
it loads the library! 

Best regards, and thanks to all,
Krystian






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:50 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register