X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Finterface.c;h=8947dd61c0160b8c833e48a872e6dd69c93c6664;hb=2b65cef7870c385b9b56b34701ced62528f3f7c0;hp=960cc6220933c78c635cdf185c39a65b8a5d5843;hpb=06adec208286b5a136ffa5c5f3832c35e9f62844;p=collectd.git diff --git a/src/interface.c b/src/interface.c index 960cc622..8947dd61 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1,6 +1,6 @@ /** * collectd - src/interface.c - * Copyright (C) 2005-2007 Florian octo Forster + * Copyright (C) 2005-2008 Florian octo Forster * * 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 @@ -46,6 +46,10 @@ # include #endif +#if HAVE_STATGRAB_H +# 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 @@ -58,49 +62,13 @@ # endif /* !COLLECT_GETIFADDRS */ #endif /* KERNEL_LINUX */ -#if HAVE_GETIFADDRS || KERNEL_LINUX || HAVE_LIBKSTAT || HAVE_LIBSTATGRAB -# define INTERFACE_HAVE_READ 1 -#else -# define INTERFACE_HAVE_READ 0 +#if !HAVE_GETIFADDRS && !KERNEL_LINUX && !HAVE_LIBKSTAT && !HAVE_LIBSTATGRAB +# error "No applicable input method." #endif /* * (Module-)Global variables */ -/* 2^32 = 4294967296 = ~4.2GByte/s = ~34GBit/s */ -static data_source_t octets_dsrc[2] = -{ - {"rx", DS_TYPE_COUNTER, 0, 4294967295.0}, - {"tx", DS_TYPE_COUNTER, 0, 4294967295.0} -}; - -static data_set_t octets_ds = -{ - "if_octets", 2, octets_dsrc -}; - -static data_source_t packets_dsrc[2] = -{ - {"rx", DS_TYPE_COUNTER, 0, 4294967295.0}, - {"tx", DS_TYPE_COUNTER, 0, 4294967295.0} -}; - -static data_set_t packets_ds = -{ - "if_packets", 2, packets_dsrc -}; - -static data_source_t errors_dsrc[2] = -{ - {"rx", DS_TYPE_COUNTER, 0, 4294967295.0}, - {"tx", DS_TYPE_COUNTER, 0, 4294967295.0} -}; - -static data_set_t errors_ds = -{ - "if_errors", 2, errors_dsrc -}; - static const char *config_keys[] = { "Interface", @@ -166,7 +134,6 @@ static int interface_config (const char *key, const char *value) #if HAVE_LIBKSTAT static int interface_init (void) { -#if HAVE_LIBKSTAT kstat_t *ksp_chain; unsigned long long val; @@ -189,7 +156,6 @@ static int interface_init (void) continue; ksp[numif++] = ksp_chain; } -#endif /* HAVE_LIBKSTAT */ return (0); } /* int interface_init */ @@ -215,7 +181,6 @@ static int check_ignore_if (const char *interface) return (1 - if_list_action); } /* int check_ignore_if */ -#if INTERFACE_HAVE_READ static void if_submit (const char *dev, const char *type, unsigned long long rx, unsigned long long tx) @@ -232,11 +197,12 @@ static void if_submit (const char *dev, const char *type, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "interface"); - strncpy (vl.type_instance, dev, sizeof (vl.type_instance)); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "interface", sizeof (vl.plugin)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, dev, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void if_submit */ static int interface_read (void) @@ -351,7 +317,7 @@ static int interface_read (void) unsigned long long tx; if (kc == NULL) - return; + return (-1); for (i = 0; i < numif; i++) { @@ -387,27 +353,13 @@ static int interface_read (void) return (0); } /* int interface_read */ -#endif /* INTERFACE_HAVE_READ */ -void module_register (modreg_e load) +void module_register (void) { - if (load & MR_DATASETS) - { - plugin_register_data_set (&octets_ds); - plugin_register_data_set (&packets_ds); - plugin_register_data_set (&errors_ds); - } - plugin_register_config ("interface", interface_config, config_keys, config_keys_num); - - if (load & MR_READ) - { #if HAVE_LIBKSTAT - plugin_register_init ("interface", interface_init); + plugin_register_init ("interface", interface_init); #endif -#if INTERFACE_HAVE_READ - plugin_register_read ("interface", interface_read); -#endif - } + plugin_register_read ("interface", interface_read); } /* void module_register */