X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Finterface.c;h=1ba6c8c32b73199823134d1662d89975065dc1d9;hb=3b4201d2235c25ed21174c41c526c9b7894de539;hp=fad37dbefdaf6208133e2454da22ac3ef2e263db;hpb=9b626288aff81c68fe19210a58b4a32eeefde9d3;p=collectd.git diff --git a/src/interface.c b/src/interface.c index fad37dbe..1ba6c8c3 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1,6 +1,7 @@ /** * collectd - src/interface.c * Copyright (C) 2005-2008 Florian octo Forster + * Copyright (C) 2009 Manuel Sanmartin * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -18,6 +19,7 @@ * Authors: * Florian octo Forster * Sune Marcher + * Manuel Sanmartin **/ #include "collectd.h" @@ -51,6 +53,11 @@ # include #endif +#if HAVE_PERFSTAT +# include +# include +#endif + /* * Various people have reported problems with `getifaddrs' and varying versions * of `glibc'. That's why it's disabled by default. Since more statistics are @@ -63,7 +70,13 @@ # endif /* !COLLECT_GETIFADDRS */ #endif /* KERNEL_LINUX */ -#if !HAVE_GETIFADDRS && !KERNEL_LINUX && !HAVE_LIBKSTAT && !HAVE_LIBSTATGRAB +#if HAVE_PERFSTAT +static perfstat_netinterface_t *ifstat; +static int nif; +static int pnif; +#endif /* HAVE_PERFSTAT */ + +#if !HAVE_GETIFADDRS && !KERNEL_LINUX && !HAVE_LIBKSTAT && !HAVE_LIBSTATGRAB && !HAVE_PERFSTAT # error "No applicable input method." #endif @@ -99,9 +112,7 @@ static int interface_config (const char *key, const char *value) else if (strcasecmp (key, "IgnoreSelected") == 0) { int invert = 1; - if ((strcasecmp (value, "True") == 0) - || (strcasecmp (value, "Yes") == 0) - || (strcasecmp (value, "On") == 0)) + if (IS_TRUE (value)) invert = 0; ignorelist_set_invert (ignorelist, invert); } @@ -224,7 +235,7 @@ static int interface_read (void) char buffer[1024]; unsigned long long incoming, outgoing; char *device; - + char *dummy; char *fields[16]; int numfields; @@ -250,7 +261,7 @@ static int interface_read (void) if (device[0] == '\0') continue; - + numfields = strsplit (dummy, fields, 16); if (numfields < 11) @@ -310,7 +321,44 @@ static int interface_read (void) for (i = 0; i < num; i++) if_submit (ios[i].interface_name, "if_octets", ios[i].rx, ios[i].tx); -#endif /* HAVE_LIBSTATGRAB */ +/* #endif HAVE_LIBSTATGRAB */ + +#elif defined(HAVE_PERFSTAT) + perfstat_id_t id; + int i, ifs; + + if ((nif = perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t), 0)) < 0) + { + char errbuf[1024]; + WARNING ("interface plugin: perfstat_netinterface: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + if (pnif != nif || ifstat == NULL) + { + if (ifstat != NULL) + free(ifstat); + ifstat = malloc(nif * sizeof(perfstat_netinterface_t)); + } + pnif = nif; + + id.name[0]='\0'; + if ((ifs = perfstat_netinterface(&id, ifstat, sizeof(perfstat_netinterface_t), nif)) < 0) + { + char errbuf[1024]; + WARNING ("interface plugin: perfstat_netinterface (interfaces=%d): %s", + nif, sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + for (i = 0; i < ifs; i++) + { + if_submit (ifstat[i].name, "if_octets", ifstat[i].ibytes, ifstat[i].obytes); + if_submit (ifstat[i].name, "if_packets", ifstat[i].ipackets ,ifstat[i].opackets); + if_submit (ifstat[i].name, "if_errors", ifstat[i].ierrors, ifstat[i].oerrors ); + } +#endif /* HAVE_PERFSTAT */ return (0); } /* int interface_read */