notes:
configure.in.patch... don't apply this under cygwin... unless you feel like fixing all the acconfig.h things.. Makefile will notice configure.in is not up to date and try to re-generate things, which won't work. I add -lrpclib to LIBS in gmond/Makefile and gmetric/Makefile (also this means I haven't tried it)

 rpcinfo.c.patch: apply this to
http://grass.itc.it/grass5/binary/windows_cygnus/sunrpc/sunrpc-4.0.cygwin1.src.tar.gz

 cygwin.c.patch:
   there are bugs,  a seg fault when running in gdb,
    cpu_system seems to sit at 50% if nothing is going on

it won't run without the attached /etc/gmond.conf..

tip:
cygrunsrv -I gmond -f "Ganglia Monitoring Daemon" --path /usr/sbin/gmond.exe
will add gmond as a NT Service..

--- ./ganglia-monitor-core-2.4.1/configure.in   2002-05-15 18:32:18.000000000 
-0700
+++ ./ganglia-monitor-core-2.4.1-cyg/configure.in       2002-08-06 
11:55:20.000000000 -0700
@@ -89,6 +89,7 @@
 AC_CHECK_LIB(odm, odm_initialize)
 AC_CHECK_LIB(cfg, _system_configuration)
 AC_CHECK_LIB(dl, dlopen)
+AC_CHECK_LIB(rpclib,xdr_bytes)
 
 dnl AC_CHECK_LIB(crypto, RSA_sign)
 dnl if test "$ac_cv_lib_crypto_RSA_sign" = no; then
--- ./ganglia-monitor-core-2.4.1/gmond/machines/cygwin.c        2002-02-01 
12:51:59.000000000 -0800
+++ ./ganglia-monitor-core-2.4.1-cyg2/gmond/machines/cygwin.c   2002-08-06 
11:43:43.000000000 -0700
@@ -1,235 +1,454 @@
-#include "metric.h"
-
+#include <sys/types.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <sys/utsname.h>
+#include "ganglia.h"
+#include "metric_typedefs.h"
 /*
- * This function is called only once by the gmond.  Use to 
- * initialize data structures, etc or just return SYNAPSE_SUCCESS;
+#include "set_metric_val.h"
  */
-int
-metric_init()
+
+typedef struct {
+  int last_read;
+  int thresh;
+  char *name;
+  char buffer[BUFFSIZE];
+} timely_file;
+static struct utsname os_info;
+timely_file proc_stat    = { 0, 15, "/proc/stat" };
+timely_file proc_loadavg = { 0, 15, "/proc/loadavg" };
+timely_file proc_meminfo = { 0, 30, "/proc/meminfo" };
+
+char *update_file(timely_file *tf)
 {
-   return SYNAPSE_SUCCESS;
+  int now,rval;
+  now = time(0);
+  if(now - tf->last_read > tf->thresh) {
+    rval = slurpfile(tf->name, tf->buffer, BUFFSIZE);
+    if(rval == SYNAPSE_FAILURE) {
+      err_msg("update_file() got an error from slurpfile() reading %s",
+              tf->name);
+    }
+    else tf->last_read = now;
+  }
+  return tf->buffer;
 }
 
-/*
- * 
+/* This function is called only once by the gmond.  Use to 
+ * initialize data structures, etc or just return SYNAPSE_SUCCESS;
  */
 
-int
-cpu_num_func ( int i )
+g_val_t
+metric_init( void )
 {
-   g_val_t val;
 
-   val.s = 2;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+  g_val_t rval; 
+  uname(&os_info);
+  rval.int32 = SYNAPSE_SUCCESS;
+  return rval;
 }
 
-int
-cpu_speed_func ( int i )
+g_val_t cpu_num_func(void)
 {
+static  char cyg_cpuinfo[] = 
"/proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor";
    g_val_t val;
+unsigned int cyg_cpu_num = 0;
+  DIR *dirp;
+  struct dirent *dp;
+  dirp = opendir (cyg_cpuinfo);
+        while ((dp = readdir(dirp))) {
+                if (dp->d_name[0] != '.')
+                {
+                               cyg_cpu_num++;
+                }
+       }
+val.uint16 = cyg_cpu_num;
+closedir(dirp);
+return val;
+}
 
-   val.s = 500;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+g_val_t
+cpu_speed_func ( void )
+{
+  static unsigned int cpu_speed;
+  g_val_t rval;
+  FILE *io;
+  io = 
fopen("/proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor/0/~MHz","rb");
+  if (io ==  NULL) {
+    printf("open failed(cpu_speed)\n");
 }
+  fread (&cpu_speed, sizeof(unsigned int),1,io);
+  fclose(io);
+  rval.uint32= cpu_speed;
+   return rval;
 
-int
-mem_total_func ( int i )
+}
+
+g_val_t
+mem_total_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.l = 512000;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = strstr( update_file(&proc_meminfo), "MemTotal:");
+   p = skip_token(p);
+   val.uint32 = strtol( p, (char **)NULL, 10 );
+
+   return val;
 }
 
-int
-swap_total_func ( int i )
+g_val_t
+swap_total_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.l = 512111;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = strstr( update_file(&proc_meminfo), "SwapTotal:");
+   p = skip_token(p);
+   val.uint32 = strtol( p, (char **)NULL, 10 );
+
+   return val;
 }
 
-int
-boottime_func ( int i )
+
+g_val_t
+boottime_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.l = 928272;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = update_file(&proc_stat);
+
+   p = strstr ( p, "btime" );
+   p = skip_token ( p );
+   val.uint32 = strtod ( p, (char **)NULL );
+
+   return val;
 }
 
-int
-sys_clock_func ( int i )
+g_val_t
+sys_clock_func ( void )
 {
    g_val_t val;
-
-   val.l = 94393292;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   val.uint32 = time(NULL);
+   return val;
 }
+g_val_t
+machine_type_func ( void )
+{
+   g_val_t val;
 
-int
-kernel_func ( int i )
+#ifdef __i386__
+   snprintf(val.str, MAX_G_STRING_SIZE, "x86");
+#endif
+#ifdef __ia64__
+   snprintf(val.str, MAX_G_STRING_SIZE, "ia64");
+#endif
+
+   return val;
+}
+g_val_t
+os_name_func ( void )
 {
    g_val_t val;
 
-   strncpy( val.str, "my kernel", MAX_G_STRING_SIZE );
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   snprintf(val.str, MAX_G_STRING_SIZE, os_info.sysname);
+
+   return val;
 }
 
-int
-cpu_user_func ( int i )
+g_val_t
+os_release_func ( void )
 {
+
    g_val_t val;
 
-   val.d = 89.9;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   snprintf(val.str, MAX_G_STRING_SIZE, "%s", os_info.release);
+   return val;
 }
 
-int
-cpu_nice_func ( int i )
+unsigned long
+total_jiffies_func ( void )
 {
-   g_val_t val;
+   char *p;
+   unsigned long user_jiffies, nice_jiffies, system_jiffies, idle_jiffies;
 
-   val.d = 12.2;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = update_file(&proc_stat);
+   p = skip_token(p);
+   p = skip_whitespace(p);
+   user_jiffies = strtod( p, &p );
+   p = skip_whitespace(p);
+   nice_jiffies = strtod( p, &p );
+   p = skip_whitespace(p);
+   system_jiffies = strtod( p , &p );
+   p = skip_whitespace(p);
+   idle_jiffies = strtod( p , &p );
+
+   return user_jiffies + nice_jiffies + system_jiffies + idle_jiffies;
 }
 
-int 
-cpu_system_func ( int i )
+
+g_val_t
+cpu_user_func ( void )
 {
-   g_val_t val;
+   char *p;
+   static g_val_t val;
+   static int stamp;
+   static double last_user_jiffies,  user_jiffies,
+                 last_total_jiffies, total_jiffies, diff;
 
-   val.d = 20.2;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = update_file(&proc_stat);
+   if(proc_stat.last_read != stamp) {
+     stamp = proc_stat.last_read;
+
+     p = skip_token(p);
+     user_jiffies  = strtod( p , (char **)NULL );
+     total_jiffies = total_jiffies_func();
+
+     diff = user_jiffies - last_user_jiffies;
+
+     if ( diff )
+       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
+     else
+       val.f = 0.0;
+
+     last_user_jiffies  = user_jiffies;
+     last_total_jiffies = total_jiffies;
+
+   }
+   return val;
 }
+g_val_t
+cpu_nice_func ( void )
+{
+   char *p;
+   static g_val_t val;
+   static int stamp;
+   static double last_nice_jiffies,  nice_jiffies,
+                 last_total_jiffies, total_jiffies, diff;
 
-int 
-cpu_idle_func ( int i )
+   p = update_file(&proc_stat);
+   if(proc_stat.last_read != stamp) {
+     stamp = proc_stat.last_read;
+
+     p = skip_token(p);
+     p = skip_token(p);
+     nice_jiffies  = strtod( p , (char **)NULL );
+     total_jiffies = total_jiffies_func();
+
+     diff = (nice_jiffies  - last_nice_jiffies);
+
+     if ( diff )
+       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
+     else
+       val.f = 0.0;
+
+     last_nice_jiffies  = nice_jiffies;
+     last_total_jiffies = total_jiffies;
+
+   }
+   return val;
+}
+
+g_val_t
+cpu_system_func ( void )
 {
-   g_val_t val;
+   char *p;
+   static g_val_t val;
+   static int stamp;
+   static double last_system_jiffies,  system_jiffies,
+                 last_total_jiffies, total_jiffies, diff;
 
-   val.d = 12.4;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = update_file(&proc_stat);
+   if(proc_stat.last_read != stamp) {
+     stamp = proc_stat.last_read;
+
+     p = skip_token(p);
+     p = skip_token(p);
+     p = skip_token(p);
+     system_jiffies = strtod( p , (char **)NULL );
+     total_jiffies  = total_jiffies_func();
+
+     diff = system_jiffies  - last_system_jiffies;
+
+     if ( diff )
+       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
+     else
+       val.f = 0.0;
+
+     last_system_jiffies  = system_jiffies;
+     last_total_jiffies = total_jiffies;
+
+   }
+   return val;
 }
 
-int 
-cpu_aidle_func ( int i )
+g_val_t
+cpu_idle_func ( void )
 {
-   g_val_t val;
+   char *p;
+   static g_val_t val;
+   static int stamp;
+   static double last_idle_jiffies,  idle_jiffies,
+                 last_total_jiffies, total_jiffies, diff;
+
+   p = update_file(&proc_stat);
+   if(proc_stat.last_read != stamp) {
+     stamp = proc_stat.last_read;
+
+     p = skip_token(p);
+     p = skip_token(p);
+     p = skip_token(p);
+     p = skip_token(p);
+     idle_jiffies  = strtod( p , (char **)NULL );
+     total_jiffies = total_jiffies_func();
+
+     diff = idle_jiffies - last_idle_jiffies;
+
+     if ( diff )
+       val.f = (diff/(total_jiffies - last_total_jiffies))*100;
+     else
+       val.f = 0.0;
+
+     last_idle_jiffies  = idle_jiffies;
+     last_total_jiffies = total_jiffies;
    
-   val.d = 50.00;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
 }
 
-int
-load_one_func ( int i )
+   return val;
+}
+
+g_val_t
+cpu_aidle_func ( uint32_t i )
 {
+   char *p;
    g_val_t val;
+   double idle_jiffies, total_jiffies;
 
-   val.d = 20.00;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = update_file(&proc_stat);
+
+   p = skip_token(p);
+   p = skip_token(p);
+   p = skip_token(p);
+   p = skip_token(p);
+   idle_jiffies  = strtod( p , (char **)NULL );
+   total_jiffies = total_jiffies_func();
+
+   val.f = (idle_jiffies/total_jiffies)*100;
+   return val;
 }
 
-int
-load_five_func ( int i )
+g_val_t
+load_one_func ( void )
 {
    g_val_t val;
  
-   val.d = 10.23;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   val.f = strtod( update_file(&proc_loadavg), (char **)NULL); 
+   return val;
 }
 
-int
-load_fifteen_func ( int i )
+g_val_t
+load_five_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.d = 3.45;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = update_file(&proc_loadavg);
+   p = skip_token(p);
+   val.f = strtod( p, (char **)NULL);
+
+   return val;
 }
 
-int
-proc_run_func( int i )
+g_val_t
+load_fifteen_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.l = 5;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = update_file(&proc_loadavg);
+
+   p = skip_token(p);
+   p = skip_token(p);
+   val.f = strtod( p, (char **)NULL);
+
+   return val;
 }
 
-int
-proc_total_func ( int i )
+g_val_t
+proc_run_func( void )
 {
    g_val_t val;
+val.uint32 = 0;
+return val;
+}
 
-   val.l = 120;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+g_val_t
+proc_total_func ( void )
+{
+  /* doesn't exist in cygwin's /proc/loadavg */ 
+   g_val_t val;
+   val.uint32 = 0;
+   return val;
 }
 
-int
-mem_free_func ( int i )
+
+g_val_t
+mem_free_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.l = 1223;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = strstr( update_file(&proc_meminfo), "MemFree:" );
+   p = skip_token(p);
+   val.uint32 = strtol( p, (char **)NULL, 10 );
+
+   return val;
 }
 
-int
-mem_shared_func ( int i )
+g_val_t
+mem_shared_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.l = 512000;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   p = strstr( update_file(&proc_meminfo), "MemShared:" );
+   p = skip_token(p);
+   val.uint32 = strtol( p, (char **)NULL, 10 );
+
+   return val;
 }
 
-int
-mem_buffers_func ( int i )
+g_val_t
+mem_buffers_func ( void )
 {
+/* does not exist in cygwins /proc/meminfo */
    g_val_t val;
+   val.uint32 = 0;
 
-   val.l = 34343;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   return val;
 }
 
-int
-mem_cached_func ( int i )
+g_val_t
+mem_cached_func ( void )
 {
+/* does not exist in cygwin's /proc/meminfo */
    g_val_t val;
+   val.uint32 = 0;
 
-   val.l = 23232;
-   set_metric_val(i, val);
-   return SYNAPSE_SUCCESS;
+   return val;
 }
 
-int
-swap_free_func ( int i )
+g_val_t
+swap_free_func ( void )
 {
+   char *p;
    g_val_t val;
 
-   val.l = 3409834;
-   set_metric_val(i, val); 
-   return SYNAPSE_SUCCESS;
+   p = strstr( update_file(&proc_meminfo), "SwapFree:" );
+   p = skip_token(p);
+   val.uint32 = strtol( p, (char **)NULL, 10 );
+
+   return val;
 }
+
diff -rb -U 5 -dNwB ./rpc-4.0/etc/rpcinfo.c rpc-cyg-4.0/etc/rpcinfo.c
--- ./rpc-4.0/etc/rpcinfo.c     1999-01-15 19:18:35.000000000 -0800
+++ rpc-cyg-4.0/etc/rpcinfo.c   2002-08-06 12:33:14.000000000 -0700
@@ -51,14 +51,14 @@
 #include <ctype.h>
 
 #ifdef __CYGWIN32__
 #include <unistd.h>
 #include <windows.h>
+#include <lm.h>
 
 #define USER_PRIV_ADMIN 2
 
-DWORD STDCALL NetUserGetInfo (LPWSTR, LPWSTR, DWORD, LPBYTE);
 #endif /* __CYGWIN32__ */
 
 #define MAXHOSTLEN 256
 
 #define        MIN_VERS        ((u_long) 0)
@@ -596,11 +596,11 @@
   WCHAR name[512];
   DWORD ret;
   PUSER_INFO_3 ui;
 
   MultiByteToWideChar (CP_ACP, 0, user, -1, name, 512);
-  ret = NetUserGetInfo (NULL, name, 3, (LPBYTE) &ui);
+  ret = NetUserGetInfo (NULL, name, 3, (LPBYTE *) &ui);
   return ret ? NULL : ui;
 }
 #endif /* __CYGWIN32__ */
 
 static void
#cygwin errors trying to join the multicast group if this isn't here
 mcast_port    8649
#cygwin errors trying to become a nobody without this 
 no_setuid  on

Reply via email to