X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finterface.c;h=d05dd72309f80ffd79c6e94fbe2c9509d962afce;hb=952a2f399229aa5e327959ba81d32dc47a4745df;hp=ea820399ca0652bc7299d2b24ee4dde9c5569ecd;hpb=3904b4b9fd1a53c93f31d8fec709a7b7b8300513;p=collectd.git diff --git a/src/interface.c b/src/interface.c index ea820399..d05dd723 100644 --- a/src/interface.c +++ b/src/interface.c @@ -17,7 +17,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster * Sune Marcher * Manuel Sanmartin **/ @@ -31,9 +31,6 @@ #if HAVE_SYS_TYPES_H # include #endif -#if HAVE_SYS_SOCKET_H -# include -#endif /* One cannot include both. This sucks. */ #if HAVE_LINUX_IF_H @@ -98,6 +95,7 @@ static ignorelist_t *ignorelist = NULL; extern kstat_ctl_t *kc; static kstat_t *ksp[MAX_NUMIF]; static int numif = 0; +static _Bool unique_name = 0; #endif /* HAVE_LIBKSTAT */ static int interface_config (const char *key, const char *value) @@ -116,6 +114,15 @@ static int interface_config (const char *key, const char *value) invert = 0; ignorelist_set_invert (ignorelist, invert); } + else if (strcasecmp (key, "UniqueName") == 0) + { + #ifdef HAVE_LIBKSTAT + if (IS_TRUE (value)) + unique_name = 1; + #else + WARNING ("interface plugin: the \"UniqueName\" option is only valid on Solaris."); + #endif /* HAVE_LIBKSTAT */ + } else { return (-1); @@ -183,7 +190,7 @@ static int interface_read (void) struct ifaddrs *if_list; struct ifaddrs *if_ptr; -/* Darin/Mac OS X and possible other *BSDs */ +/* Darwin/Mac OS X and possible other *BSDs */ #if HAVE_STRUCT_IF_DATA # define IFA_DATA if_data # define IFA_RX_BYTES ifi_ibytes @@ -213,18 +220,19 @@ static int interface_read (void) for (if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next) { - if ((if_data = (struct IFA_DATA *) if_ptr->ifa_data) == NULL) - continue; + if (if_ptr->ifa_addr != NULL && if_ptr->ifa_addr->sa_family == AF_LINK) { + if_data = (struct IFA_DATA *) if_ptr->ifa_data; - if_submit (if_ptr->ifa_name, "if_octets", + if_submit (if_ptr->ifa_name, "if_octets", if_data->IFA_RX_BYTES, if_data->IFA_TX_BYTES); - if_submit (if_ptr->ifa_name, "if_packets", + if_submit (if_ptr->ifa_name, "if_packets", if_data->IFA_RX_PACKT, if_data->IFA_TX_PACKT); - if_submit (if_ptr->ifa_name, "if_errors", + if_submit (if_ptr->ifa_name, "if_errors", if_data->IFA_RX_ERROR, if_data->IFA_TX_ERROR); + } } freeifaddrs (if_list); @@ -278,6 +286,10 @@ static int interface_read (void) incoming = atoll (fields[2]); outgoing = atoll (fields[10]); if_submit (device, "if_errors", incoming, outgoing); + + incoming = atoll (fields[3]); + outgoing = atoll (fields[11]); + if_submit (device, "if_dropped", incoming, outgoing); } fclose (fh); @@ -287,6 +299,7 @@ static int interface_read (void) int i; derive_t rx; derive_t tx; + char iname[DATA_MAX_NAME_LEN]; if (kc == NULL) return (-1); @@ -296,6 +309,11 @@ static int interface_read (void) if (kstat_read (kc, ksp[i], NULL) == -1) continue; + if (unique_name) + ssnprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module, ksp[i]->ks_instance, ksp[i]->ks_name); + else + sstrncpy(iname, ksp[i]->ks_name, sizeof(iname)); + /* try to get 64bit counters */ rx = get_kstat_value (ksp[i], "rbytes64"); tx = get_kstat_value (ksp[i], "obytes64"); @@ -305,7 +323,7 @@ static int interface_read (void) if (tx == -1LL) tx = get_kstat_value (ksp[i], "obytes"); if ((rx != -1LL) || (tx != -1LL)) - if_submit (ksp[i]->ks_name, "if_octets", rx, tx); + if_submit (iname, "if_octets", rx, tx); /* try to get 64bit counters */ rx = get_kstat_value (ksp[i], "ipackets64"); @@ -316,13 +334,13 @@ static int interface_read (void) if (tx == -1LL) tx = get_kstat_value (ksp[i], "opackets"); if ((rx != -1LL) || (tx != -1LL)) - if_submit (ksp[i]->ks_name, "if_packets", rx, tx); + if_submit (iname, "if_packets", rx, tx); /* no 64bit error counters yet */ rx = get_kstat_value (ksp[i], "ierrors"); tx = get_kstat_value (ksp[i], "oerrors"); if ((rx != -1LL) || (tx != -1LL)) - if_submit (ksp[i]->ks_name, "if_errors", rx, tx); + if_submit (iname, "if_errors", rx, tx); } /* #endif HAVE_LIBKSTAT */ @@ -350,9 +368,8 @@ static int interface_read (void) if (pnif != nif || ifstat == NULL) { - if (ifstat != NULL) - free(ifstat); - ifstat = malloc(nif * sizeof(perfstat_netinterface_t)); + free(ifstat); + ifstat = malloc(nif * sizeof (*ifstat)); } pnif = nif;