X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Finterface.c;h=c618af98c0016dacb5950aad50b017c3e0858c34;hb=affac33e83584e7538c358e3bd0a587d0c692bc3;hp=177afbaa0847b8f1db0dac2dd89bf6d6bf8bb19e;hpb=cc3640ba512862cd5745446f1f1a997dd4344454;p=collectd.git diff --git a/src/interface.c b/src/interface.c index 177afbaa..c618af98 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1,6 +1,6 @@ /** * collectd - src/interface.c - * Copyright (C) 2005-2008 Florian octo Forster + * Copyright (C) 2005-2010 Florian octo Forster * Copyright (C) 2009 Manuel Sanmartin * * This program is free software; you can redistribute it and/or modify it @@ -128,7 +128,7 @@ static int interface_config (const char *key, const char *value) static int interface_init (void) { kstat_t *ksp_chain; - unsigned long long val; + derive_t val; numif = 0; @@ -155,8 +155,8 @@ static int interface_init (void) #endif /* HAVE_LIBKSTAT */ static void if_submit (const char *dev, const char *type, - unsigned long long rx, - unsigned long long tx) + derive_t rx, + derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; @@ -164,8 +164,8 @@ static void if_submit (const char *dev, const char *type, if (ignorelist_match (ignorelist, dev) != 0) return; - values[0].counter = rx; - values[1].counter = tx; + values[0].derive = rx; + values[1].derive = tx; vl.values = values; vl.values_len = 2; @@ -213,18 +213,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); @@ -233,7 +234,7 @@ static int interface_read (void) #elif KERNEL_LINUX FILE *fh; char buffer[1024]; - unsigned long long incoming, outgoing; + derive_t incoming, outgoing; char *device; char *dummy; @@ -285,8 +286,8 @@ static int interface_read (void) #elif HAVE_LIBKSTAT int i; - unsigned long long rx; - unsigned long long tx; + derive_t rx; + derive_t tx; if (kc == NULL) return (-1); @@ -296,16 +297,29 @@ static int interface_read (void) if (kstat_read (kc, ksp[i], NULL) == -1) continue; - rx = get_kstat_value (ksp[i], "rbytes"); - tx = get_kstat_value (ksp[i], "obytes"); + /* try to get 64bit counters */ + rx = get_kstat_value (ksp[i], "rbytes64"); + tx = get_kstat_value (ksp[i], "obytes64"); + /* or fallback to 32bit */ + if (rx == -1LL) + rx = get_kstat_value (ksp[i], "rbytes"); + 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); - rx = get_kstat_value (ksp[i], "ipackets"); - tx = get_kstat_value (ksp[i], "opackets"); + /* try to get 64bit counters */ + rx = get_kstat_value (ksp[i], "ipackets64"); + tx = get_kstat_value (ksp[i], "opackets64"); + /* or fallback to 32bit */ + if (rx == -1LL) + rx = get_kstat_value (ksp[i], "ipackets"); + 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); + /* no 64bit error counters yet */ rx = get_kstat_value (ksp[i], "ierrors"); tx = get_kstat_value (ksp[i], "oerrors"); if ((rx != -1LL) || (tx != -1LL))