From: octo Date: Wed, 26 Apr 2006 09:37:47 +0000 (+0000) Subject: Added `package' and `errors' counter for libkstat to the `traffic' plugin. X-Git-Tag: svn-trunk~40 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=21ebd2852e1f8e2c9991bf02fe2e9e56317608dd;p=collectd.git Added `package' and `errors' counter for libkstat to the `traffic' plugin. --- diff --git a/src/traffic.c b/src/traffic.c index 7bbc4814..713b01a4 100644 --- a/src/traffic.c +++ b/src/traffic.c @@ -59,6 +59,7 @@ static char *bytes_file = "traffic-%s.rrd"; static char *packets_file = "if_packets-%s.rrd"; static char *errors_file = "if_errors-%s.rrd"; +/* TODO: Maybe implement multicast and broadcast counters */ static char *bytes_ds_def[] = { @@ -177,7 +178,7 @@ static void bytes_submit (char *device, plugin_submit (MODULE_NAME, device, buf); } -#if HAVE_GETIFADDRS +#if HAVE_GETIFADDRS || HAVE_LIBKSTAT static void packets_submit (char *dev, unsigned long long rx, unsigned long long tx) @@ -207,7 +208,7 @@ static void errors_submit (char *dev, return; plugin_submit ("if_errors", dev, buf); } -#endif /* HAVE_GETIFADDRS */ +#endif /* HAVE_GETIFADDRS || HAVE_LIBKSTAT */ static void traffic_read (void) { @@ -306,9 +307,10 @@ static void traffic_read (void) fclose (fh); /* #endif KERNEL_LINUX */ -#elif defined(HAVE_LIBKSTAT) +#elif HAVE_LIBKSTAT int i; - unsigned long long incoming, outgoing; + unsigned long long rx; + unsigned long long tx; if (kc == NULL) return; @@ -318,12 +320,20 @@ static void traffic_read (void) if (kstat_read (kc, ksp[i], NULL) == -1) continue; - if ((incoming = get_kstat_value (ksp[i], "rbytes")) == -1LL) - continue; - if ((outgoing = get_kstat_value (ksp[i], "obytes")) == -1LL) - continue; + rx = get_kstat_value (ksp[i], "rbytes"); + tx = get_kstat_value (ksp[i], "obytes"); + if ((rx != -1LL) || (tx != -1LL)) + bytes_submit (ksp[i]->ks_name, rx, tx); + + rx = get_kstat_value (ksp[i], "ipackets"); + tx = get_kstat_value (ksp[i], "opackets"); + if ((rx != -1LL) || (tx != -1LL)) + packets_submit (ksp[i]->ks_name, rx, tx); - bytes_submit (ksp[i]->ks_name, incoming, outgoing); + rx = get_kstat_value (ksp[i], "ierrors"); + tx = get_kstat_value (ksp[i], "oerrors"); + if ((rx != -1LL) || (tx != -1LL)) + errors_submit (ksp[i]->ks_name, rx, tx); } /* #endif HAVE_LIBKSTAT */