Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/pr/1416'
Browse files Browse the repository at this point in the history
  • Loading branch information
octo committed Dec 8, 2015
2 parents 584f57c + 5f7f9b9 commit 1c8063a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/collectd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@
#<Plugin interface>
# Interface "eth0"
# IgnoreSelected false
# UniqueName false
#</Plugin>

#<Plugin ipmi>
Expand Down
11 changes: 11 additions & 0 deletions src/collectd.conf.pod
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,17 @@ do that: By setting B<IgnoreSelected> to I<true> the effect of
B<Interface> is inverted: All selected interfaces are ignored and all
other interfaces are collected.

=item B<UniqueName> I<true>|I<false>

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<http://docs.oracle.com/cd/E23824_01/html/821-1468/kstat-3kstat.html#REFMAN3Ekstat-3kstat>

This option is only available on Solaris.

=back

=head2 Plugin C<ipmi>
Expand Down
22 changes: 19 additions & 3 deletions src/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,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)
Expand All @@ -113,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);
Expand Down Expand Up @@ -285,6 +295,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);
Expand All @@ -294,6 +305,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");
Expand All @@ -303,7 +319,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");
Expand All @@ -314,13 +330,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 */

Expand Down

0 comments on commit 1c8063a

Please sign in to comment.