Greetings, The following patch, fixes the metrics for network traffic on cygwin which were trying to use a non existent /proc/net/dev interface by using instead a native win32 call to gather the MIB_II interface list and attributes.
as a sideffect this patch also enables additional OS specific metrics which where left undefined since the move of the monitors to the libmetrics sub package and which was affecting most of the supported OS and add the OS specific metrics to the cygwin platform, including the standalone tests. this patch applies to the current CVS version for monitor-core (2.5.8 alike) and has been tested on FC3 and Windows XP Carlo
diff --exclude CVS -rc monitor-core.netcygwin/configure.in monitor-core/configure.in *** monitor-core.netcygwin/configure.in 2004-11-22 02:23:36.000000000 -0800 --- monitor-core/configure.in 2004-11-21 17:34:24.000000000 -0800 *************** *** 346,352 **** AC_DEFINE(SUPPORT_GEXEC, 0, SUPPORT_GEXEC) AC_DEFINE(FREEBSD, 1, FREEBSD);; *cygwin*) metric_source="cygwin.c" - LDFLAGS="-liphlpapi" AC_DEFINE(CYGWIN,1,CYGWIN) esac --- 346,351 ---- diff --exclude CVS -rc monitor-core.netcygwin/gmond/gmond.c monitor-core/gmond/gmond.c *** monitor-core.netcygwin/gmond/gmond.c 2004-11-21 22:56:22.000000000 -0800 --- monitor-core/gmond/gmond.c 2004-11-21 17:34:25.000000000 -0800 *************** *** 134,148 **** #endif - #ifdef CYGWIN - , - KEY(bytes_out), 4096, 30, 40, 200, 300, g_float, "bytes/sec", "%.2f" }, - KEY(bytes_in), 4096, 30, 40, 200, 300, g_float, "bytes/sec", "%.2f" }, - KEY(pkts_in), 256, 30, 40, 200, 300, g_float, "packets/sec", "%.2f" }, - KEY(pkts_out), 256, 30, 40, 200, 300, g_float, "packets/sec", "%.2f" } - - #endif - #ifdef HPUX , KEY(cpu_intr), 1, 15, 20, 60, 90, g_float, "%", "%.1f"}, --- 134,139 ---- diff --exclude CVS -rc monitor-core.netcygwin/gmond/metric.h monitor-core/gmond/metric.h *** monitor-core.netcygwin/gmond/metric.h 2004-11-22 02:33:35.000000000 -0800 --- monitor-core/gmond/metric.h 2004-11-21 17:34:25.000000000 -0800 *************** *** 101,115 **** #endif - #ifdef CYGWIN - - extern g_val_t bytes_in_func(void); - extern g_val_t bytes_out_func(void); - extern g_val_t pkts_in_func(void); - extern g_val_t pkts_out_func(void); - - #endif - #ifdef HPUX extern g_val_t cpu_wait_func(void); --- 101,106 ---- diff --exclude CVS -rc monitor-core.netcygwin/srclib/libmetrics/cygwin/Makefile.am monitor-core/srclib/libmetrics/cygwin/Makefile.am *** monitor-core.netcygwin/srclib/libmetrics/cygwin/Makefile.am 2004-11-22 02:15:43.000000000 -0800 --- monitor-core/srclib/libmetrics/cygwin/Makefile.am 2004-11-17 18:23:15.000000000 -0800 *************** *** 1,6 **** AM_CFLAGS=-I.. -I$(top_builddir)/lib - AM_LDFLAGS=-liphlpapi - noinst_LTLIBRARIES = libmetric25.la ! libmetric25_la_SOURCES = metrics.c --- 1,4 ---- AM_CFLAGS=-I.. -I$(top_builddir)/lib noinst_LTLIBRARIES = libmetric25.la ! libmetric25_la_SOURCES = metrics.c diff --exclude CVS -rc monitor-core.netcygwin/srclib/libmetrics/cygwin/metrics.c monitor-core/srclib/libmetrics/cygwin/metrics.c *** monitor-core.netcygwin/srclib/libmetrics/cygwin/metrics.c 2004-11-22 04:04:12.641075807 -0800 --- monitor-core/srclib/libmetrics/cygwin/metrics.c 2004-11-19 12:01:44.000000000 -0800 *************** *** 4,12 **** #include <time.h> #include <unistd.h> #include <ctype.h> - #include <windows.h> - #include <iphlpapi.h> - #include <sys/timeb.h> /* From old ganglia 2.5.x... */ #include "file.h" --- 4,9 ---- *************** *** 30,84 **** timely_file proc_stat = { 0, 15, "/proc/stat" }; timely_file proc_loadavg = { 0, 15, "/proc/loadavg" }; timely_file proc_meminfo = { 0, 30, "/proc/meminfo" }; ! ! static time_t ! get_netbw(double *in_bytes, double *out_bytes, ! double *in_pkts, double *out_pkts) ! { ! PMIB_IFTABLE iftable; ! double bytes_in = 0, bytes_out = 0, pkts_in = 0, pkts_out = 0; ! static DWORD dwSize; ! DWORD ret, dwInterface; ! struct timeb timebuffer; ! PMIB_IFROW ifrow; ! ! dwSize = sizeof(MIB_IFTABLE); ! ! iftable = (PMIB_IFTABLE) malloc (dwSize); ! while (ret = GetIfTable(iftable, &dwSize, 1) == ERROR_INSUFFICIENT_BUFFER) { ! iftable = (PMIB_IFTABLE) realloc (iftable, dwSize); ! } ! ! if (ret == NO_ERROR) { ! ! _ftime ( &timebuffer ); ! ! /* scan the interface table */ ! for (dwInterface = 0; dwInterface < (iftable -> dwNumEntries); dwInterface++) { ! ifrow = &(iftable -> table[dwInterface]); ! ! /* exclude loopback */ ! if ( (ifrow -> dwType != MIB_IF_TYPE_LOOPBACK ) && (ifrow -> dwOperStatus ==MIB_IF_OPER_STATUS_OPERATIONAL ) ) { ! bytes_in += ifrow -> dwInOctets; ! bytes_out += ifrow -> dwOutOctets; ! ! /* does not include multicast traffic (dw{In,Out}NUcastPkts) */ ! pkts_in += ifrow -> dwInUcastPkts; ! pkts_out += ifrow -> dwOutUcastPkts; ! } ! } ! free (iftable); ! } else { ! err_msg("get_netbw() got an error from GetIfTable()"); ! } ! ! if (in_bytes) *in_bytes = bytes_in; ! if (out_bytes) *out_bytes = bytes_out; ! if (in_pkts) *in_pkts = pkts_in; ! if (out_pkts) *out_pkts = pkts_out; ! ! return timebuffer.time; ! } char *update_file(timely_file *tf) { --- 27,33 ---- timely_file proc_stat = { 0, 15, "/proc/stat" }; timely_file proc_loadavg = { 0, 15, "/proc/loadavg" }; timely_file proc_meminfo = { 0, 30, "/proc/meminfo" }; ! timely_file proc_net_dev = { 0, 30, "/proc/net/dev" }; char *update_file(timely_file *tf) { *************** *** 150,155 **** --- 99,111 ---- strcpy( proc_sys_kernel_osrelease, "cygwin" ); + rval.int32 = (int) update_file(&proc_net_dev); + if ( rval.int32 == SYNAPSE_FAILURE ) + { + err_msg("net_dev_func() got an error from slurpfile()"); + return rval; + } + rval.int32 = SYNAPSE_SUCCESS; return rval; } *************** *** 157,256 **** g_val_t pkts_in_func ( void ) { ! double in_pkts=0, t=0; ! time_t stamp; ! static time_t last_stamp; ! static double last_pkts_in; ! g_val_t val; ! unsigned long diff; ! ! stamp = get_netbw(NULL, NULL, &in_pkts, NULL); ! (unsigned long) diff = in_pkts - last_pkts_in; ! if ( diff && last_stamp ) { ! t = stamp - last_stamp; ! t = diff / t; ! debug_msg("Returning value: %f\n", t); ! } else t = 0; ! ! val.f = t; ! last_pkts_in = in_pkts; ! last_stamp = stamp; return val; } g_val_t pkts_out_func ( void ) { ! double out_pkts=0, t=0; ! time_t stamp; ! static time_t last_stamp; ! static double last_pkts_out; ! g_val_t val; ! unsigned long diff; ! ! stamp = get_netbw(NULL, NULL, NULL, &out_pkts); ! (unsigned long) diff = out_pkts - last_pkts_out; ! if ( diff && last_stamp ) { ! t = stamp - last_stamp; ! t = diff / t; ! debug_msg("Returning value: %f\n", t); ! } else t = 0; ! ! val.f = t; ! last_pkts_out = out_pkts; ! last_stamp = stamp; return val; } g_val_t bytes_out_func ( void ) { ! double out_bytes=0, t=0; ! time_t stamp; ! static time_t last_stamp; ! static double last_bytes_out; ! g_val_t val; ! unsigned long diff; ! ! stamp = get_netbw(NULL, &out_bytes, NULL, NULL); ! (unsigned long) diff = out_bytes - last_bytes_out; ! if ( diff && last_stamp ) { ! t = stamp - last_stamp; ! t = diff / t; ! debug_msg("Returning value: %f\n", t); ! } else t = 0; ! ! val.f = t; ! last_bytes_out = out_bytes; ! last_stamp = stamp; return val; } g_val_t bytes_in_func ( void ) { ! double in_bytes=0, t=0; ! time_t stamp; ! static time_t last_stamp; ! static double last_bytes_in; ! g_val_t val; ! unsigned long diff; ! ! stamp = get_netbw(&in_bytes, NULL, NULL, NULL); ! (unsigned long) diff = in_bytes - last_bytes_in; ! if ( diff && last_stamp ) { ! t = stamp - last_stamp; ! t = diff / t; ! debug_msg("Returning value: %f\n", t); ! } else t = 0; ! ! val.f = t; ! last_bytes_in = in_bytes; ! last_stamp = stamp; return val; } --- 113,356 ---- g_val_t pkts_in_func ( void ) { ! char *p; ! register int i; ! static g_val_t val; ! int size; ! static int stamp; ! static double last_bytes_in, ! last_bytes_out, ! last_pkts_in, ! last_pkts_out; ! double bytes_in=0, bytes_out=0, pkts_in=0, pkts_out=0, t = 0; ! unsigned long diff; ! p = update_file(&proc_net_dev); ! if (proc_net_dev.last_read != stamp) { ! ! size = ( index (p, 0x00) ) - p; ! /* skip past the two-line header ... */ ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; // and skip loopback, which is always the first one ! while (*p != 0x00 ) ! { ! p = index(p, ':')+1; /* skip past the interface tag portion of this line */ ! if ( (*p-1 != 'o') && (*p-2 != 'l') ) ! { ! t = strtod( p, &p ); ! bytes_in += t; ! t = strtod( p, &p ); ! pkts_in += t; ! for (i = 0; i < 6; i++) strtol(p, &p, 10); ! t = strtod( p, &p ); ! bytes_out += t; ! pkts_out += strtod( p, &p ); ! } ! p = index (p, '\n') + 1; // skips a line ! } ! (unsigned long) diff = pkts_in - last_pkts_in; ! if ( diff ) ! { ! t = proc_net_dev.last_read - stamp; ! t = diff / t; ! debug_msg("Returning value: %f\n",t); ! } ! else ! t = 0; ! val.f = t; ! ! last_bytes_in = bytes_in; ! last_pkts_in = pkts_in; ! last_pkts_out = pkts_out; ! last_bytes_out = bytes_out; ! ! stamp = proc_net_dev.last_read; + } return val; } g_val_t pkts_out_func ( void ) { ! char *p; ! register int i; ! static g_val_t val; ! int size; ! static int stamp; ! static double last_bytes_in, ! last_bytes_out, ! last_pkts_in, ! last_pkts_out; ! double bytes_in=0, bytes_out=0, pkts_in=0, pkts_out=0, t = 0; ! unsigned long diff; ! p = update_file(&proc_net_dev); ! if (proc_net_dev.last_read != stamp) { ! ! size = ( index (p, 0x00) ) - p; ! /* skip past the two-line header ... */ ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; // and skip loopback, which is always the first one ! while (*p != 0x00 ) ! { ! p = index(p, ':')+1; /* skip past the interface tag portion of this line */ ! if ( (*p-1 != 'o') && (*p-2 != 'l') ) ! { ! t = strtod( p, &p ); ! bytes_in += t; ! t = strtod( p, &p ); ! pkts_in += t; ! for (i = 0; i < 6; i++) strtol(p, &p, 10); ! t = strtod( p, &p ); ! bytes_out += t; ! pkts_out += strtod( p, &p ); ! } ! p = index (p, '\n') + 1; // skips a line ! } ! (unsigned long) diff = pkts_out - last_pkts_out; ! if ( diff ) ! { ! t = proc_net_dev.last_read - stamp; ! t = diff / t; ! } ! else ! t = 0; ! val.f = t; ! ! last_bytes_in = bytes_in; ! last_pkts_in = pkts_in; ! last_pkts_out = pkts_out; ! last_bytes_out = bytes_out; + stamp = proc_net_dev.last_read; + + } return val; } g_val_t bytes_out_func ( void ) { ! char *p; ! register int i; ! static g_val_t val; ! int size; ! static int stamp; ! static double last_bytes_in, ! last_bytes_out, ! last_pkts_in, ! last_pkts_out; ! double bytes_in=0, bytes_out=0, pkts_in=0, pkts_out=0, t = 0; ! unsigned long diff; ! p = update_file(&proc_net_dev); ! if (proc_net_dev.last_read != stamp) { ! ! size = ( index (p, 0x00) ) - p; ! /* skip past the two-line header ... */ ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; // and skip loopback, which is always the first one ! while (*p != 0x00 ) ! { ! p = index(p, ':')+1; /* skip past the interface tag portion of this line */ ! if ( (*p-1 != 'o') && (*p-2 != 'l') ) ! { ! t = strtod( p, &p ); ! bytes_in += t; ! t = strtod( p, &p ); ! pkts_in += t; ! for (i = 0; i < 6; i++) strtol(p, &p, 10); ! /* Fixed 2003 by Dr Michael Wirtz <[EMAIL PROTECTED]> ! and Phil Radden <[EMAIL PROTECTED]> */ ! t = strtod( p, &p ); ! bytes_out += t; ! pkts_out += strtod( p, &p ); ! } ! p = index (p, '\n') + 1; // skips a line ! } ! (unsigned long) diff = bytes_out - last_bytes_out; ! if ( diff ) ! { ! t = proc_net_dev.last_read - stamp; ! t = diff / t; ! } ! else ! t = 0; ! val.f = t; ! ! last_bytes_in = bytes_in; ! last_pkts_in = pkts_in; ! last_pkts_out = pkts_out; ! last_bytes_out = bytes_out; ! ! stamp = proc_net_dev.last_read; + } + debug_msg(" ********** BYTES_OUT RETURN: %f", val.f); return val; } g_val_t bytes_in_func ( void ) { ! char *p; ! register int i; ! static g_val_t val; ! int size; ! static int stamp; ! static double last_bytes_in, ! last_bytes_out, ! last_pkts_in, ! last_pkts_out; ! double bytes_in=0, bytes_out=0, pkts_in=0, pkts_out=0, t = 0; ! unsigned long diff; ! p = update_file(&proc_net_dev); ! if (proc_net_dev.last_read != stamp) { ! ! size = ( index (p, 0x00) ) - p; ! /* skip past the two-line header ... */ ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; ! p = index (p, '\n')+1; // and skip loopback, which is always the first one ! while (*p != 0x00 ) ! { ! p = index(p, ':')+1; /* skip past the interface tag portion of this line */ ! debug_msg(" Last two chars: %c%c\n", *p-2, *p-1 ); ! if ( (*p-1 != 'o') && (*p-2 != 'l') ) ! { ! debug_msg(" Last two chars: %c%c\n", *p-2, *p-1 ); ! t = strtod( p, &p ); ! bytes_in += t; ! t = strtod( p, &p ); ! pkts_in += t; ! for (i = 0; i < 6; i++) strtol(p, &p, 10); ! /* Fixed 2003 by Dr Michael Wirtz <[EMAIL PROTECTED]> ! and Phil Radden <[EMAIL PROTECTED]>. */ ! t = strtod( p, &p ); ! bytes_out += t; ! pkts_out += strtod( p, &p ); ! } ! p = index (p, '\n') + 1; // skips a line ! } ! (unsigned long) diff = bytes_in - last_bytes_in; ! if ( diff ) ! { ! t = proc_net_dev.last_read - stamp; ! t = diff / t; ! } ! else ! t = 0; ! val.f = t; ! ! last_bytes_in = bytes_in; ! last_pkts_in = pkts_in; ! last_pkts_out = pkts_out; ! last_bytes_out = bytes_out; + stamp = proc_net_dev.last_read; + + } return val; } diff --exclude CVS -rc monitor-core.netcygwin/srclib/libmetrics/libmetrics.h monitor-core/srclib/libmetrics/libmetrics.h *** monitor-core.netcygwin/srclib/libmetrics/libmetrics.h 2004-11-21 22:07:57.000000000 -0800 --- monitor-core/srclib/libmetrics/libmetrics.h 2004-11-18 12:14:34.000000000 -0800 *************** *** 13,22 **** #include <sys/types.h> #include <rpc/types.h> - #ifdef HAVE_CONFIG_H - #include <config.h> - #endif - typedef enum { g_string, /* huh uh.. he said g string */ g_int8, --- 13,18 ---- *************** *** 112,126 **** #endif - #ifdef CYGWIN - - g_val_t bytes_in_func(void); - g_val_t bytes_out_func(void); - g_val_t pkts_in_func(void); - g_val_t pkts_out_func(void); - - #endif - #ifdef HPUX g_val_t cpu_intr_func(void); --- 108,113 ---- *************** *** 204,215 **** disk_free, part_max_used, #endif - #ifdef CYGWIN - bytes_in, - bytes_out, - pkts_in, - pkgs_out, - #endif #ifdef HPUX cpu_intr, cpu_ssys, --- 191,196 ---- diff --exclude CVS -rc monitor-core.netcygwin/srclib/libmetrics/tests/test-metrics.c monitor-core/srclib/libmetrics/tests/test-metrics.c *** monitor-core.netcygwin/srclib/libmetrics/tests/test-metrics.c 2004-11-22 02:17:24.000000000 -0800 --- monitor-core/srclib/libmetrics/tests/test-metrics.c 2004-11-17 18:23:19.000000000 -0800 *************** *** 64,79 **** "swap_free", swap_free_func, g_uint32}, { "mtu", mtu_func, g_uint32}, - #ifdef CYGWIN - { - "bytes_out", bytes_out_func, g_float}, - { - "bytes_in", bytes_in_func, g_float}, - { - "pkts_in", pkts_in_func, g_float}, - { - "pkts_out", pkts_out_func, g_float}, - #endif { "", NULL} }; --- 64,69 ----