From af9e12790d8097f358bac8d70d744f682c6929b7 Mon Sep 17 00:00:00 2001 From: Yoga Ramalingam Date: Mon, 7 Dec 2015 15:59:39 -0500 Subject: [PATCH] interface plugin: Fix review comments. Issue: #1416 --- src/collectd.conf.in | 1 + src/collectd.conf.pod | 11 +++++++++++ src/interface.c | 10 +++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index eb230235..a75bcc04 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -564,6 +564,7 @@ # # Interface "eth0" # IgnoreSelected false +# UniqueName false # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index a5af5762..ff950911 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -2525,6 +2525,17 @@ do that: By setting B to I the effect of B is inverted: All selected interfaces are ignored and all other interfaces are collected. +=item B I|I + +Interface name is not unique on Solaris (KSTAT), interface name is unique +only within a module/instance. Following tuple is considered unique: + (ks_module, ks_instance, ks_name) +If this option is set to true, interface name contains above three fields +separated by an underscore. For more info on KSTAT, visit +L + +This option is only available on Solaris. + =back =head2 Plugin C diff --git a/src/interface.c b/src/interface.c index d9a0db3a..1c01f6ff 100644 --- a/src/interface.c +++ b/src/interface.c @@ -89,13 +89,13 @@ static const char *config_keys[] = static int config_keys_num = 2; static ignorelist_t *ignorelist = NULL; -static _Bool unique_name = 0; #ifdef HAVE_LIBKSTAT #define MAX_NUMIF 256 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,8 +116,12 @@ static int interface_config (const char *key, const char *value) } 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 { @@ -302,9 +306,9 @@ static int interface_read (void) continue; if (unique_name) - snprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module, ksp[i]->ks_instance, ksp[i]->ks_name); + ssnprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module, ksp[i]->ks_instance, ksp[i]->ks_name); else - snprintf(iname, sizeof(iname), "%s", ksp[i]->ks_name); + sstrncpy(iname, ksp[i]->ks_name, sizeof(iname)); /* try to get 64bit counters */ rx = get_kstat_value (ksp[i], "rbytes64"); -- 2.11.0