diff -ur ganglia-monitor-core-2.5.3/gmond/machines/hpux.c ganglia-monitor-core-2.5.3-work//gmond/machines/hpux.c --- ganglia-monitor-core-2.5.3/gmond/machines/hpux.c Fri Mar 7 20:59:19 2003 +++ ganglia-monitor-core-2.5.3-work//gmond/machines/hpux.c Fri May 9 14:11:28 2003 @@ -178,7 +178,7 @@ if( -1 == uname(&uts)) { - err_ret("machine_type_func() got an error from uname()"); + err_ret("os_name_func() got an error from uname()"); strncpy( val.str, "HP-UX", MAX_G_STRING_SIZE); } else @@ -195,7 +195,7 @@ if( -1 == uname(&uts)) { - err_ret("machine_type_func() got an error from uname()"); + err_ret("os_release_func() got an error from uname()"); strncpy( val.str, "unknown", MAX_G_STRING_SIZE); } else @@ -422,7 +422,7 @@ case LOAD_5: val.f = p.psd_avg_5_min; break; case LOAD_15: val.f = p.psd_avg_15_min; break; default: - err_sys("swap_func() - invalid value for which = %d", which); + err_sys("load_func() - invalid value for which = %d", which); } return val; diff -ur ganglia-monitor-core-2.5.3/gmond/machines/irix.c ganglia-monitor-core-2.5.3-work//gmond/machines/irix.c --- ganglia-monitor-core-2.5.3/gmond/machines/irix.c Fri May 9 14:27:54 2003 +++ ganglia-monitor-core-2.5.3-work//gmond/machines/irix.c Fri May 9 14:21:31 2003 @@ -1,3 +1,28 @@ +/* + * irix.c - Ganglia monitor core gmond module for IRIX + * + * Change log: + * + * 15apr2002 - unknown ??? + * Initial version + * + * 06may2003 - Martin Knoblauch + * Minimum mtu is now actually computed + * CPU speed is taken from "sgikopt", assuming all CPUs in + * the system run at the same speed. + * bootime is computed correctly + * Add wait, interrupt and swap times to "system" time metric + * Add stub for standalone testing + * Add some FIXME comments, just as reminders :-) + * + * 08may2003 - Martin Knoblauch + * Add "cached" memory metrics. Don't ask why I know :-) + * Add "shared" memory metrics. See special comment. + * Add "total" and "running" processes. + * Add "aidle" cpu percentage. "nice" is the last missing metric. + * + */ + #include "ganglia.h" #include "metric_typedefs.h" #include @@ -180,21 +205,6 @@ } g_val_t -mem_total_func ( void ) -{ - g_val_t val; - sgt_cookie_t cookie; - int mem[1]; - - SGT_COOKIE_INIT(&cookie); - SGT_COOKIE_SET_KSYM(&cookie, "physmem"); - sysget(SGT_KSYM, (char *)mem, sizeof(mem), - SGT_READ, &cookie); - val.uint32 = ( mem[0] * multiplier); - return val; -} - -g_val_t swap_total_func ( void ) { g_val_t val; @@ -307,13 +317,21 @@ { g_val_t val; - /* FIXME ?? IRIX */ + recalculate_cpu_percentages(); val.f = 0.0; + if (cpuinfo.total != 0) + val.f = ((float)cpuinfo.idle / (float)cpuinfo.total)*100.; return val; } +/* + * Implement helper function for load values. + * Add error output + */ +enum {LOAD_1, LOAD_5, LOAD_15}; + g_val_t -load_one_func ( void ) +load_func ( int which ) { g_val_t val; sgt_cookie_t cookie; @@ -321,110 +339,229 @@ SGT_COOKIE_INIT(&cookie); SGT_COOKIE_SET_KSYM(&cookie, "avenrun"); - sysget(SGT_KSYM, (char *)avenrun, sizeof(avenrun), - SGT_READ, &cookie); - val.f = ( (float) avenrun[0] ) / 1024.0; + if (sysget(SGT_KSYM, (char *)avenrun, sizeof(avenrun), + SGT_READ, &cookie) == -1) + { + perror("sysget AVENRUN"); + val.f = 0.0; + } + else + val.f = ( (float) avenrun[which] ) / 1024.0; + return val; } g_val_t -load_five_func ( void ) +load_one_func ( void ) { - g_val_t val; - sgt_cookie_t cookie; - int avenrun[3]; + return load_func( LOAD_1 ); +} - SGT_COOKIE_INIT(&cookie); - SGT_COOKIE_SET_KSYM(&cookie, "avenrun"); - sysget(SGT_KSYM, (char *)avenrun, sizeof(avenrun), - SGT_READ, &cookie); - val.f = ( (float) avenrun[1] ) / 1024.0; - return val; +g_val_t +load_five_func ( void ) +{ + return load_func( LOAD_5 ); } g_val_t load_fifteen_func ( void ) { - g_val_t val; - sgt_cookie_t cookie; - int avenrun[3]; + return load_func( LOAD_15 ); +} - SGT_COOKIE_INIT(&cookie); - SGT_COOKIE_SET_KSYM(&cookie, "avenrun"); - sysget(SGT_KSYM, (char *)avenrun, sizeof(avenrun), - SGT_READ, &cookie); - val.f = ( (float) avenrun[2] ) / 1024.0; - return val; +#include +#include + +static int dbuf[4096]; +static char pfilename[512]; +enum {PROC_TOTAL, PROC_RUNNING}; +/* + * Helper function for processes. + */ +g_val_t +proc_func( int which ) +{ +g_val_t val; +int pfd,pffd,nlen,deof,i; +unsigned int totp,runp; +struct dirent *sdirp; +struct prpsinfo prpsi; +char *cdirp; + + val.uint32 = 0; +/* + * On IRIX, "/proc/pinfo" contains non-priviledged readable process entries. + * We try to open this directory now. + */ + if ((pfd = open("/proc/pinfo", O_RDONLY|O_NONBLOCK)) == -1) + { + perror("proc_func: open pinfo directory failed"); + } + else + { +/* + * Now we try to loop over all pseudo files in "/proc/pinfo". + * First we need to get a list of all "dirent" entries. + */ + totp = runp = 0; + do + { +/* + * Try to get 16384 bytes worth of "dirent" data. If "deof" is 1, we got all of them + */ + if ((nlen = ngetdents(pfd, (struct dirent *)&dbuf[0], 16384, &deof)) == -1) + { + perror("proc_func: ngetdents failed"); + close(pfd); + return val; + } + else + { +/* + * Here we loop over the set of dirent structures returned by "ngetdents". As the + * size of the actual entries is variable, we need to do some pointer math :-( + */ + for (i = 0; i < nlen; ) + { +/* + * Calculate address of next "dirent" structure + */ + cdirp = ((char *)&dbuf[0]) + i; + sdirp = (struct dirent *)cdirp; + i += sdirp->d_reclen; +/* + * Discard "." and ".." entries + */ + if(strpbrk(sdirp->d_name,".")) continue; +/* + * Every remaining file points to a process. Just increment number of total processes here. + */ + totp++; + if (which == PROC_TOTAL) continue; +/* + * Lets try to open the process file for reading + */ + strcpy(pfilename,"/proc/pinfo/"); + strcat(pfilename,sdirp->d_name); + if ((pffd = open(pfilename, O_RDONLY)) == -1) + { + perror("proc_func: opening process file failed"); + printf("pfile: %s\n",pfilename); + } + else + { +/* + * Now do an ioctl call to get to the "prpsinfo" data + */ + if(ioctl(pffd, PIOCPSINFO, &prpsi) == -1) + { + perror("proc_func: ioctl on process file failed"); + } + else + { + if(prpsi.pr_sname == 'R') + { +// printf("pid = %d %d %d (%c) %s\n", +// prpsi.pr_pid,prpsi.pr_flag,prpsi.pr_state,prpsi.pr_sname,prpsi.pr_fname); + runp++; + } + } + close(pffd); + } + } + } + } while ( deof == 0) ; + close (pfd); + switch (which) { + case PROC_TOTAL: val.uint32 = totp; break; + case PROC_RUNNING: val.uint32 = runp; break; + default: break; + } + } + + return val; } g_val_t proc_run_func( void ) { - g_val_t val; - - /* FIXME !! IRIX */ - val.uint32 = 0; - return val; + return proc_func( PROC_RUNNING ); } g_val_t proc_total_func ( void ) { - g_val_t val; + return proc_func( PROC_TOTAL ); +} - /* FIXME !! IRIX */ - val.uint32 = 0; - return val; +/* + * Implement helper function for various memory metrics. + */ +enum {MEM_TOTAL, MEM_FREE, MEM_SHARED, MEM_BUFFERS, MEM_CACHED}; + +g_val_t +mem_func( int which ) +{ + g_val_t val; + struct rminfo rmi; + + val.uint32 = 0; + if (sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(struct rminfo)) == -1) + { + perror("sysmp failed in mem_func"); + } + else + { + switch (which) + { + case MEM_TOTAL: val.uint32 = rmi.physmem*multiplier; break; + case MEM_FREE: val.uint32 = rmi.freemem*multiplier; break; + case MEM_SHARED: val.uint32 = (rmi.dchunkpages+rmi.dpages)*multiplier; break; + case MEM_BUFFERS: val.uint32 = rmi.bufmem*multiplier; break; + case MEM_CACHED: val.uint32 = (rmi.chunkpages-rmi.dchunkpages)*multiplier; break; + default: + err_msg("mem_func() - invalid value for which = %d", which); + } + } + return val; } g_val_t -mem_free_func ( void ) +mem_total_func ( void ) { - g_val_t val; - sgt_cookie_t cookie; - int mem[1]; + return mem_func( MEM_TOTAL ); +} - SGT_COOKIE_INIT(&cookie); - SGT_COOKIE_SET_KSYM(&cookie, "freemem"); - sysget(SGT_KSYM, (char *)mem, sizeof(mem), - SGT_READ, &cookie); - val.uint32 = ( mem[0] * multiplier); - return val; +g_val_t +mem_free_func ( void ) +{ + return mem_func( MEM_FREE ); } +/* + * MKN: "shared" is the amount of dirty cached memory. I did this, because + * I couldn't find any other useful deployment of this base metric. + * + */ g_val_t mem_shared_func ( void ) { - g_val_t val; - - /* FIXME ?? IRIX */ - val.uint32 = 0; - return val; + return mem_func( MEM_SHARED ); } g_val_t mem_buffers_func ( void ) { - g_val_t val; - sgt_cookie_t cookie; - int mem[1]; - - SGT_COOKIE_INIT(&cookie); - SGT_COOKIE_SET_KSYM(&cookie, "bufmem"); - sysget(SGT_KSYM, (char *)mem, sizeof(mem), - SGT_READ, &cookie); - val.uint32 = ( mem[0] * multiplier); - return val; + return mem_func( MEM_BUFFERS ); } +/* + * MKN: This shows the amount of "clean" cached memory. + */ g_val_t mem_cached_func ( void ) { - g_val_t val; - - /* FIXME ?? IRIX */ - val.uint32 = 0; - return val; + return mem_func( MEM_CACHED ); } g_val_t @@ -440,17 +577,48 @@ /* ---------------------------------- */ - +/* + * Stub for doing stand-alone testing + * + * Compile with: + * + * + gcc -DHAVE_CONFIG_H -I.. -I../lib -I../lib/dnet -g -O2 -Wall \ + -D_IRIX_SOURCE -DSTAND_ALONE_TEST machine.c \ + ../lib/.libs/libganglia.a ../lib/libdnet.a -o bla + * + */ #ifdef STAND_ALONE_TEST -main() +int main() { g_val_t tval; metric_init(); -tval = mtu_func(); -printf("mtu: %d\n",tval.uint32); +proc_func ( 0 ); + +mem_func(0); + +tval = mem_total_func(); +printf("Total Memory: %f\n",tval.uint32/1024.); +tval = mem_free_func(); +printf("Free Memory: %f\n",tval.uint32/1024.); +tval = mem_shared_func(); +printf("Shared Memory: %f\n",tval.uint32/1024.); +tval = mem_buffers_func(); +printf("Buffer Memory: %f\n",tval.uint32/1024.); +tval = mem_cached_func(); +printf("Cached Memory: %f\n",tval.uint32/1024.); + +tval = proc_total_func(); +printf("Tot proc: %d\n",tval.uint32); +tval = proc_run_func(); +printf("Run proc: %d\n",tval.uint32); + +tval = cpu_aidle_func(); +printf("aidlepct = %f\n",tval.f); +return 0; } #endif