Merge branch 'pr/1791'
authorFlorian Forster <octo@collectd.org>
Mon, 1 Aug 2016 09:12:48 +0000 (11:12 +0200)
committerFlorian Forster <octo@collectd.org>
Mon, 1 Aug 2016 09:12:48 +0000 (11:12 +0200)
1  2 
src/collectd.conf.pod
src/interface.c

diff --combined src/collectd.conf.pod
@@@ -2735,6 -2735,18 +2735,18 @@@ This will ignore the loopback interface
  with I<veth> and all interfaces with names starting with I<tun> followed by
  at least one digit.
  
+ =item B<ReportInactive> I<true>|I<false>
+ When set to I<false>, only interfaces with non-zero traffic will be
+ reported. Note that the check is done by looking into whether a
+ package was sent at any time from boot and the corresponding counter
+ is non-zero. So, if the interface has been sending data in the past
+ since boot, but not during the reported time-interval, it will still
+ be reported.
+ The default value is I<true> and results in collection of the data
+ from all interfaces that are selected by B<Interface> and
+ B<IgnoreSelected> options.
  
  =item B<UniqueName> I<true>|I<false>
  
@@@ -6456,22 -6468,6 +6468,22 @@@ collected. If at least one B<Disk> opti
  set to B<false>, B<only> matching disks will be collected. If B<IgnoreSelected>
  is set to B<true>, all disks are collected B<except> the ones matched.
  
 +=item B<IgnoreSleepMode> B<true>|B<false>
 +
 +Normally, the C<smart> plugin will ignore disks that are reported to be asleep.
 +This option disables the sleep mode check and allows the plugin to collect data
 +from these disks anyway. This is useful in cases where libatasmart mistakenly
 +reports disks as asleep because it has not been updated to incorporate support
 +for newer idle states in the ATA spec.
 +
 +=item B<UseSerial> B<true>|B<false>
 +
 +A disk's kernel name (e.g., sda) can change from one boot to the next. If this
 +option is enabled, the C<smart> plugin will use the disk's serial number (e.g.,
 +HGST_HUH728080ALE600_2EJ8VH8X) instead of the kernel name as the key for
 +storing data. This ensures that the data for a given disk will be kept together
 +even if the kernel name changes.
 +
  =back
  
  =head2 Plugin C<snmp>
@@@ -7809,12 -7805,11 +7821,12 @@@ Define which SSL protocol version must 
  attempt to figure out the remote SSL protocol version. See
  L<curl_easy_setopt(3)> for more details.
  
 -=item B<Format> B<Command>|B<JSON>
 +=item B<Format> B<Command>|B<JSON>|B<KAIROSDB>
  
  Format of the output to generate. If set to B<Command>, will create output that
  is understood by the I<Exec> and I<UnixSock> plugins. When set to B<JSON>, will
 -create output in the I<JavaScript Object Notation> (JSON).
 +create output in the I<JavaScript Object Notation> (JSON). When set to KAIROSDB
 +, will create output in the KairosDB format.
  
  Defaults to B<Command>.
  
diff --combined src/interface.c
@@@ -84,12 -84,14 +84,14 @@@ static const char *config_keys[] 
  {
        "Interface",
        "IgnoreSelected",
-       NULL
+       "ReportInactive",
  };
- static int config_keys_num = 2;
+ static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
  
  static ignorelist_t *ignorelist = NULL;
  
+ static _Bool report_inactive = 1;
  #ifdef HAVE_LIBKSTAT
  #define MAX_NUMIF 256
  extern kstat_ctl_t *kc;
@@@ -114,6 -116,8 +116,8 @@@ static int interface_config (const cha
                        invert = 0;
                ignorelist_set_invert (ignorelist, invert);
        }
+       else if (strcasecmp (key, "ReportInactive") == 0)
+               report_inactive = IS_TRUE (value);
        else if (strcasecmp (key, "UniqueName") == 0)
        {
                #ifdef HAVE_LIBKSTAT
  static int interface_init (void)
  {
        kstat_t *ksp_chain;
 -      derive_t val;
  
        numif = 0;
  
                        continue;
                if (kstat_read (kc, ksp_chain, NULL) == -1)
                        continue;
 -              if ((val = get_kstat_value (ksp_chain, "obytes")) == -1LL)
 +              if (get_kstat_value (ksp_chain, "obytes") == -1LL)
                        continue;
                ksp[numif++] = ksp_chain;
        }
@@@ -222,6 -227,9 +226,9 @@@ static int interface_read (void
                if (if_ptr->ifa_addr != NULL && if_ptr->ifa_addr->sa_family == AF_LINK) {
                        if_data = (struct IFA_DATA *) if_ptr->ifa_data;
  
+                       if (!report_inactive && if_data->IFA_RX_PACKT == 0 && if_data->IFA_TX_PACKT == 0)
+                               continue;
                        if_submit (if_ptr->ifa_name, "if_octets",
                                if_data->IFA_RX_BYTES,
                                if_data->IFA_TX_BYTES);
                if (numfields < 11)
                        continue;
  
-               incoming = atoll (fields[0]);
-               outgoing = atoll (fields[8]);
-               if_submit (device, "if_octets", incoming, outgoing);
                incoming = atoll (fields[1]);
                outgoing = atoll (fields[9]);
+               if (!report_inactive && incoming == 0 && outgoing == 0)
+                       continue;
                if_submit (device, "if_packets", incoming, outgoing);
  
+               incoming = atoll (fields[0]);
+               outgoing = atoll (fields[8]);
+               if_submit (device, "if_octets", incoming, outgoing);
                incoming = atoll (fields[2]);
                outgoing = atoll (fields[10]);
                if_submit (device, "if_errors", incoming, outgoing);
                        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");
+               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], "rbytes");
+                       rx = get_kstat_value (ksp[i], "ipackets");
                if (tx == -1LL)
-                       tx = get_kstat_value (ksp[i], "obytes");
+                       tx = get_kstat_value (ksp[i], "opackets");
+               if (!report_inactive && rx == 0 && tx == 0)
+                       continue;
                if ((rx != -1LL) || (tx != -1LL))
-                       if_submit (iname, "if_octets", rx, tx);
+                       if_submit (iname, "if_packets", rx, tx);
  
                /* try to get 64bit counters */
-               rx = get_kstat_value (ksp[i], "ipackets64");
-               tx = get_kstat_value (ksp[i], "opackets64");
+               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], "ipackets");
+                       rx = get_kstat_value (ksp[i], "rbytes");
                if (tx == -1LL)
-                       tx = get_kstat_value (ksp[i], "opackets");
+                       tx = get_kstat_value (ksp[i], "obytes");
                if ((rx != -1LL) || (tx != -1LL))
-                       if_submit (iname, "if_packets", rx, tx);
+                       if_submit (iname, "if_octets", rx, tx);
  
                /* no 64bit error counters yet */
                rx = get_kstat_value (ksp[i], "ierrors");
  
        ios = sg_get_network_io_stats (&num);
  
-       for (i = 0; i < num; i++)
+       for (i = 0; i < num; i++) {
+               if (!report_inactive && ios[i].rx == 0 && ios[i].tx == 0)
+                       continue;
                if_submit (ios[i].interface_name, "if_octets", ios[i].rx, ios[i].tx);
+       }
  /* #endif HAVE_LIBSTATGRAB */
  
  #elif defined(HAVE_PERFSTAT)
  
        for (i = 0; i < ifs; i++)
        {
+               if (!report_inactive && ifstat[i].ipackets == 0 && ifstat[i].opackets == 0)
+                       continue;
                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 );
@@@ -401,3 -420,4 +419,4 @@@ void module_register (void
  #endif
        plugin_register_read ("interface", interface_read);
  } /* void module_register */