Replace update_ifdata with a newer version that scans all interfaces and
collects metrics for all of them explicitly.
The first snippet is most likely not needed
Signed-off-by: Carlo Marcelo Arenas Belon <[EMAIL PROTECTED]>
---
trunk/monitor-core/libmetrics/aix/metrics.c | 191 +++++++++++++++++++--------
1 files changed, 137 insertions(+), 54 deletions(-)
diff --git a/trunk/monitor-core/libmetrics/aix/metrics.c
b/trunk/monitor-core/libmetrics/aix/metrics.c
index 8c0c2c7..1758375 100644
--- a/trunk/monitor-core/libmetrics/aix/metrics.c
+++ b/trunk/monitor-core/libmetrics/aix/metrics.c
@@ -43,6 +43,11 @@
#include <sys/utsname.h>
#include <sys/proc.h>
+#if !defined(_AIX43)
+#include <sys/dr.h>
+#endif
+#include <sys/systemcfg.h>
+
#include <libperfstat.h>
#include "libmetrics.h"
@@ -85,8 +90,13 @@ struct product {
#define MAX_CPUS 64
-#define INFO_TIMEOUT (5.0)
-#define CPUINFO_TIMEOUT INFO_TIMEOUT
+#define INFO_TIMEOUT (5.0)
+#define CPUINFO_TIMEOUT INFO_TIMEOUT
+#define NETWORKINFO_TIMEOUT INFO_TIMEOUT
+
+#ifndef FIRST_NETINTERFACE
+#define FIRST_NETINTERFACE ""
+#endif
#define MEM_KB_PER_PAGE (4096/1024)
@@ -97,10 +107,6 @@ struct net_stat{
double obytes;
} cur_net_stat;
-int ni_flag=0;
-
-perfstat_netinterface_total_t ninfo[2],*last_ninfo, *cur_ninfo ;
-
struct cpuinfo_stats {
double user;
double sys;
@@ -362,17 +368,17 @@ cpu_sintr_func ( void )
return val;
}
-
g_val_t
bytes_in_func ( void )
{
g_val_t val;
+
update_ifdata();
val.f = cur_net_stat.ibytes;
+
return val;
}
-
g_val_t
bytes_out_func ( void )
{
@@ -384,7 +390,6 @@ bytes_out_func ( void )
return val;
}
-
g_val_t
pkts_in_func ( void )
{
@@ -396,13 +401,11 @@ pkts_in_func ( void )
return val;
}
-
g_val_t
pkts_out_func ( void )
{
g_val_t val;
-
update_ifdata();
val.f = cur_net_stat.opackets;
@@ -847,57 +850,137 @@ int bos_level(int *aix_version, int *aix_release, int
*aix_level, int *aix_fix)
} /* bos_level */
-#define CALC_NETSTAT(type) (double)
((cur_ninfo->type<last_ninfo->type)?-1:(cur_ninfo->type -
last_ninfo->type)/timediff)
void
-update_ifdata(void){
-
+update_ifdata( void )
+{
static int init_done = 0;
- static struct timeval lasttime={0,0};
- struct timeval thistime;
- double timediff;
-
-
- /*
- ** Compute time between calls
- */
- gettimeofday (&thistime, NULL);
- if (lasttime.tv_sec)
- timediff = ((double) thistime.tv_sec * 1.0e6 +
- (double) thistime.tv_usec -
- (double) lasttime.tv_sec * 1.0e6 -
- (double) lasttime.tv_usec) / 1.0e6;
- else
- timediff = 1.0;
+ perfstat_id_t name;
+ perfstat_netinterface_t *nif_buf, *p;
+ static u_longlong_t last_bytes_in = 0L;
+ static u_longlong_t last_bytes_out = 0L;
+ static u_longlong_t last_pkts_in = 0L;
+ static u_longlong_t last_pkts_out = 0L;
+ u_longlong_t bytes_in, bytes_out, pkts_in, pkts_out;
+ longlong_t d;
+ int i, nr_netif;
+ static double last_time = 0.0;
+ double now, delta_t;
+ struct timeval timeValue;
+ struct timezone timeZone;
+
+ gettimeofday( &timeValue, &timeZone );
- /*
- ** Do nothing if we are called to soon after the last call
- */
- if (init_done && (timediff < INFO_TIMEOUT)) return;
+ now = (double) (timeValue.tv_sec - boottime) + (timeValue.tv_usec /
1000000.0);
+ delta_t = now - last_time;
- lasttime = thistime;
+/* Do nothing if we are called too soon after the last call */
+ if (init_done && (delta_t < NETWORKINFO_TIMEOUT)) return;
+
+/* obtain the network parameters */
+ bytes_in = bytes_out = pkts_in = pkts_out = 0L;
+
+ nr_netif = perfstat_netinterface( NULL, NULL, sizeof(
perfstat_netinterface_t ), 0 );
+
+ if (nr_netif == -1)
+ return;
+ else {
+/* We can allocate enough memory for the buffer */
+ nif_buf = (perfstat_netinterface_t *)
+ malloc( nr_netif * sizeof( perfstat_netinterface_t));
+
+ if (nif_buf == NULL)
+/* couldn't allocate enough memory */
+ return;
+ else {
+/* In order to get all of the network interfaces statistics,
+ * we will first ask for the network interface which name is "",
+ * that can be considered as an alias for the name of the first
+ * network interface.
+ */
+ strcpy( name.name, FIRST_NETINTERFACE );
+ if (perfstat_netinterface( &name,
+ nif_buf,
+ sizeof( perfstat_netinterface_t ),
+ nr_netif ) == -1) {
+ free( nif_buf );
+ return;
+ } else {
+/* Ok, we could get the statistics, we can now use it. */
+/* Ignore all loopback devices */
+ for (i = 0, p = nif_buf; i < nr_netif; i++, p++ )
+ if (p->type != IFT_LOOP)
+ {
+ bytes_in += p->ibytes;
+ bytes_out += p->obytes;
+ pkts_in += p->ipackets;
+ pkts_out += p->opackets;
+ }
+ }
+
+/* free allocated memory again */
+ free( nif_buf );
+ }
+ }
- last_ninfo = &ninfo[ni_flag];
- ni_flag^=1;
+/* calculate the network parameters */
+ if (init_done)
+ {
+/* get the number of bytes transferred in, check for integer overrun */
+ d = bytes_in - last_bytes_in;
+ if (d < 0) d += ULONG_MAX;
+ if ( delta_t )
+ cur_net_stat.ibytes = (double) d / delta_t;
+ else
+ cur_net_stat.ibytes = 0.0;
- cur_ninfo = &ninfo[ni_flag];
+ last_bytes_in = bytes_in;
- perfstat_netinterface_total(NULL, cur_ninfo,
sizeof(perfstat_netinterface_total_t), 1);
+/* get the number of bytes transferred out, check for integer overrun */
+ d = bytes_out - last_bytes_out;
+ if (d < 0) d += ULONG_MAX;
- if (init_done) {
- cur_net_stat.ipackets =
(CALC_NETSTAT(ipackets)<0)?cur_net_stat.ipackets:CALC_NETSTAT(ipackets);
- cur_net_stat.opackets =
(CALC_NETSTAT(opackets)<0)?cur_net_stat.opackets:CALC_NETSTAT(opackets);
- cur_net_stat.ibytes = (CALC_NETSTAT(ibytes )
<0)?cur_net_stat.ibytes:CALC_NETSTAT(ibytes );
- cur_net_stat.obytes = (CALC_NETSTAT(obytes
)<0)?cur_net_stat.obytes:CALC_NETSTAT(obytes );
- }
- else
- {
- init_done = 1;
+ if ( delta_t )
+ cur_net_stat.obytes = (double) d / delta_t;
+ else
+ cur_net_stat.obytes = 0.0;
- cur_net_stat.ipackets = 0;
- cur_net_stat.opackets = 0;
- cur_net_stat.ibytes = 0;
- cur_net_stat.obytes = 0;
- }
+ last_bytes_out = bytes_out;
+
+/* get the number of packets transferred in, check for integer overrun */
+ d = pkts_in - last_pkts_in;
+ if (d < 0) d += ULONG_MAX;
+
+ if ( delta_t )
+ cur_net_stat.ipackets = (double) d / delta_t;
+ else
+ cur_net_stat.ipackets = 0.0;
-} /* update_ifdata */
+ last_pkts_in = pkts_in;
+
+/* get the number of packets transferred out, check for integer overrun */
+ d = pkts_out - last_pkts_out;
+ if (d < 0) d += ULONG_MAX;
+
+ if ( delta_t )
+ cur_net_stat.opackets = (double) d / delta_t;
+ else
+ cur_net_stat.opackets = 0.0;
+
+ last_pkts_out = pkts_out;
+ } else {
+ init_done = 1;
+
+ cur_net_stat.ibytes = 0.0;
+ cur_net_stat.obytes = 0.0;
+ cur_net_stat.ipackets = 0.0;
+ cur_net_stat.opackets = 0.0;
+
+ last_bytes_in = bytes_in;
+ last_bytes_out = bytes_out;
+ last_pkts_in = pkts_in;
+ last_pkts_out = pkts_out;
+ }
+
+ last_time = now;
+}
--
1.5.3.7
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ganglia-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ganglia-developers