]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
infiniband plugin: initial commit
authorLuke Yeager <lyeager@nvidia.com>
Tue, 23 Jun 2020 22:51:28 +0000 (15:51 -0700)
committerLuke Yeager <lyeager@nvidia.com>
Thu, 2 Jul 2020 20:59:26 +0000 (13:59 -0700)
COPYING
Makefile.am
README
configure.ac
src/collectd.conf.in
src/collectd.conf.pod
src/infiniband.c [new file with mode: 0644]
src/types.db

diff --git a/COPYING b/COPYING
index 191af71e0574c70c7ab2a74a0dc64381a24887bb..4808f7857ba6fab07fb6741aa13cc16620ce534a 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -2,11 +2,12 @@ collectd consists of a daemon and numerous plugins. The daemon is licensed
 under the "MIT License"; its source files are located at src/daemon/. The
 plugins are licenses individually, please check the top of the plugin's source
 file(s) to see which license applies. The majority of plugins is licensed
-either under the "MIT License" or the "GNU General Public License".
+under the "MIT License" or the "GNU General Public License" or the "Apache
+License".
 
-The "MIT License" and "GNU General Public License" follow. Other licenses, not
-included in this file, should be considered "as published by the Open Source
-Initiative (OSI)".
+The "MIT License", "GNU General Public License", and "Apache License" follow.
+Other licenses, not included in this file, should be considered "as published
+by the Open Source Initiative (OSI)".
 
 MIT License
 ===========
@@ -369,3 +370,207 @@ proprietary programs.  If your program is a subroutine library, you may
 consider it more useful to permit linking proprietary applications with the
 library.  If this is what you want to do, use the GNU Lesser General
 Public License instead of this License.
+
+Apache License
+==============
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
index cb8205fccb001184da9ce71b179ba1e144450810..6f7f3c01bc6aa3c6f18f008dd1b5c281262786e7 100644 (file)
@@ -1131,6 +1131,12 @@ hugepages_la_SOURCES = src/hugepages.c
 hugepages_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 endif
 
+if BUILD_PLUGIN_INFINIBAND
+pkglib_LTLIBRARIES += infiniband.la
+infiniband_la_SOURCES = src/infiniband.c
+infiniband_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+endif
+
 if BUILD_PLUGIN_INTEL_PMU
 pkglib_LTLIBRARIES += intel_pmu.la
 intel_pmu_la_SOURCES = \
diff --git a/README b/README
index b13192f1bde4bebf967a6040a35e0b301a0d360f..e42e9c24a8d68e2ad594074147ca831b6d3831b7 100644 (file)
--- a/README
+++ b/README
@@ -172,6 +172,9 @@ Features
       This plugin should be compiled with compiler defenses enabled, for
       example -fstack-protector.
 
+    - infiniband
+      Attributes and counters for each port on each IB device.
+
     - intel_pmu
       The intel_pmu plugin reads performance counters provided by the Linux
       kernel perf interface. The plugin uses jevents library to resolve named
index 45b94ce0d2a6c7d207b27fd89698d7aba36f60fa..9d769f21e49c2bc6ebcc4df094a7d4e6c083976e 100644 (file)
@@ -6595,6 +6595,7 @@ plugin_gps="no"
 plugin_gpu_nvidia="no"
 plugin_grpc="no"
 plugin_hugepages="no"
+plugin_infiniband="no"
 plugin_intel_pmu="no"
 plugin_intel_rdt="no"
 plugin_interface="no"
@@ -6659,6 +6660,7 @@ if test "x$ac_system" = "xLinux"; then
   plugin_fhcount="yes"
   plugin_fscache="yes"
   plugin_hugepages="yes"
+  plugin_infiniband="yes"
   plugin_interface="yes"
   plugin_ipc="yes"
   plugin_irq="yes"
@@ -7057,6 +7059,7 @@ AC_PLUGIN([gpu_nvidia],          [$with_cuda],                [NVIDIA GPU plugin
 AC_PLUGIN([grpc],                [$plugin_grpc],              [gRPC plugin])
 AC_PLUGIN([hddtemp],             [yes],                       [Query hddtempd])
 AC_PLUGIN([hugepages],           [$plugin_hugepages],         [Hugepages statistics])
+AC_PLUGIN([infiniband],          [$plugin_infiniband],        [Infiniband statistics])
 AC_PLUGIN([intel_pmu],           [$with_libjevents],          [Intel performance monitor plugin])
 AC_PLUGIN([intel_rdt],           [$with_libpqos],             [Intel RDT monitor plugin])
 AC_PLUGIN([interface],           [$plugin_interface],         [Interface traffic statistics])
@@ -7502,6 +7505,7 @@ AC_MSG_RESULT([    gpu_nvidia  . . . . . $enable_gpu_nvidia])
 AC_MSG_RESULT([    grpc  . . . . . . . . $enable_grpc])
 AC_MSG_RESULT([    hddtemp . . . . . . . $enable_hddtemp])
 AC_MSG_RESULT([    hugepages . . . . . . $enable_hugepages])
+AC_MSG_RESULT([    infiniband  . . . . . $enable_infiniband])
 AC_MSG_RESULT([    intel_pmu . . . . . . $enable_intel_pmu])
 AC_MSG_RESULT([    intel_rdt . . . . . . $enable_intel_rdt])
 AC_MSG_RESULT([    interface . . . . . . $enable_interface])
index 16b222076fdbb5015f6635708b66fc708b96ba03..cebb9cbd0af69b9a8f1e3c4e07f5a9abe9ef122b 100644 (file)
 #@BUILD_PLUGIN_GRPC_TRUE@LoadPlugin grpc
 #@BUILD_PLUGIN_HDDTEMP_TRUE@LoadPlugin hddtemp
 #@BUILD_PLUGIN_HUGEPAGES_TRUE@LoadPlugin hugepages
+#@BUILD_PLUGIN_INFINIBAND_TRUE@LoadPlugin infiniband
 #@BUILD_PLUGIN_INTEL_PMU_TRUE@LoadPlugin intel_pmu
 #@BUILD_PLUGIN_INTEL_RDT_TRUE@LoadPlugin intel_rdt
 @BUILD_PLUGIN_INTERFACE_TRUE@@BUILD_PLUGIN_INTERFACE_TRUE@LoadPlugin interface
index 3b2516ef6774d08e14496b8b957fd1aac7c494b0..d45f6e86ef3d3bb4595ef57fa0db3fd4e3d5da9c 100644 (file)
@@ -3710,6 +3710,39 @@ Defaults to B<false>.
 
 =back
 
+=head2 Plugin C<infiniband>
+
+The C<infiniband> plugin collects information about IB ports. Metrics are
+gathered from C</sys/class/infiniband/DEVICE/port/PORTNUM/*>, and I<Port> names
+are formatted like C<DEVICE:PORTNUM> (see examples below).
+
+B<Options:>
+
+=over 4
+
+=item B<Port> I<Port>
+
+Select the port I<Port>. Whether it is collected or ignored depends on the
+B<IgnoreSelected> setting, see below. As with other plugins that use the
+daemon's ignorelist functionality, a string that starts and ends with a slash
+is interpreted as a regular expression. Examples:
+
+  Port "mlx5_0:1"
+  Port "/mthca0:[0-9]/"
+
+See F</"IGNORELISTS"> for details.
+
+=item B<IgnoreSelected> I<true>|I<false>
+
+Sets whether selected ports are ignored or if all other ports are ignored. The
+behavior (hopefully) is intuitive: If no B<Port> option is configured, all
+ports are collected. If at least one B<Port> option is given and
+B<IgnoreSelected> is not given or set to I<false>, B<only> matching ports will
+be collected. If B<IgnoreSelected> is set to B<true>, all ports are collected
+B<except> the ones matched.
+
+=back
+
 =head2 Plugin C<intel_pmu>
 
 The I<intel_pmu> plugin collects performance counters data on Intel CPUs using
diff --git a/src/infiniband.c b/src/infiniband.c
new file mode 100644 (file)
index 0000000..e08fe22
--- /dev/null
@@ -0,0 +1,333 @@
+/**
+ * collectd - src/infiniband.c
+ *
+ * Copyright 2002 NVIDIA Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Authors:
+ *   Luke Yeager <lyeager at nvidia.com>
+ **/
+
+#include "collectd.h"
+
+#include "plugin.h"
+#include "utils/common/common.h"
+#include "utils/ignorelist/ignorelist.h"
+
+#if !KERNEL_LINUX
+#error "No applicable input method."
+#endif
+
+#include <ctype.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Configuration settings ****************************************************/
+
+static const char *config_keys[] = {
+    "Port",
+    "IgnoreSelected",
+};
+static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
+static ignorelist_t *ignorelist;
+
+/* Listing ports *************************************************************/
+
+static int ib_glob_ports(glob_t *g) {
+  return glob("/sys/class/infiniband/*/ports/*/state", GLOB_NOSORT, NULL, g);
+}
+
+static int ib_parse_glob_port(char *path, char **device, char **port) {
+  char *tok, *saveptr = NULL;
+  int j = 0;
+  *device = NULL;
+  *port = NULL;
+  tok = strtok_r(path, "/", &saveptr);
+  while (tok != NULL) {
+    if (j == 3)
+      *device = tok;
+    else if (j == 5) {
+      *port = tok;
+      break;
+    }
+    j++;
+    tok = strtok_r(NULL, "/", &saveptr);
+  }
+  return (*device != NULL && *port != NULL) ? 0 : 1;
+}
+
+/* Core functions ************************************************************/
+
+static int ib_read_value_file(const char *device, const char *port,
+                              const char *filename, int ds_type, value_t *dst) {
+  char path[PATH_MAX];
+  if (snprintf(path, PATH_MAX, "/sys/class/infiniband/%s/ports/%s/%s", device,
+               port, filename) < 0)
+    return 1;
+  if (parse_value_file(path, dst, ds_type) != 0)
+    return 1;
+  return 0;
+}
+
+/*
+ * Used to parse files like this:
+ * rate:       "100 Gb/sec"
+ * state:      "4: ACTIVE"
+ * phys_state: "5: LinkUp"
+ */
+static int ib_read_value_file_num_only(const char *device, const char *port,
+                                       const char *filename, int ds_type,
+                                       value_t *dst) {
+  char path[PATH_MAX];
+  FILE *fh;
+  char buffer[256];
+
+  if (snprintf(path, PATH_MAX, "/sys/class/infiniband/%s/ports/%s/%s", device,
+               port, filename) < 0)
+    return 1;
+
+  // copied from parse_value_file()
+  fh = fopen(path, "r");
+  if (fh == NULL)
+    return 1;
+  if (fgets(buffer, sizeof(buffer), fh) == NULL) {
+    fclose(fh);
+    return 1;
+  }
+  fclose(fh);
+  strstripnewline(buffer);
+
+  // zero-out the first non-digit character
+  for (int i = 0; i < sizeof(buffer); i++) {
+    if (!isdigit(buffer[i])) {
+      buffer[i] = '\0';
+      break;
+    }
+  }
+
+  return parse_value(buffer, dst, ds_type);
+}
+
+static void ib_submit(const char *device, const char *port, value_t *vs, int vc,
+                      const char *type, const char *type_instance) {
+  value_list_t vl = VALUE_LIST_INIT;
+  vl.values = vs;
+  vl.values_len = vc;
+  sstrncpy(vl.plugin, "infiniband", sizeof(vl.plugin));
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s:%s", device,
+           port);
+  sstrncpy(vl.type, type, sizeof(vl.type));
+  sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
+  plugin_dispatch_values(&vl);
+}
+
+/**
+ * For further reading on the available sysfs files, see:
+ * - Linux: ./Documentation/infiniband/sysfs.txt
+ *
+ * For further reading on the meaning of each counter, see the InfiniBand
+ *   Architecture Specification, sections 14.2.5.6 and 16.1.3.5.
+ **/
+static int ib_read_port(const char *device, const char *port) {
+  value_t value, values[2];
+
+  /* PortInfo attributes */
+
+  if (ib_read_value_file_num_only(device, port, "state", DS_TYPE_GAUGE,
+                                  &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_state", "");
+  if (ib_read_value_file_num_only(device, port, "phys_state", DS_TYPE_GAUGE,
+                                  &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_phys_state", "");
+  if (ib_read_value_file_num_only(device, port, "rate", DS_TYPE_GAUGE,
+                                  &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_rate", ""); // units are Gb/s
+  if (ib_read_value_file(device, port, "cap_mask", DS_TYPE_GAUGE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_cap_mask", "");
+  if (ib_read_value_file(device, port, "lid", DS_TYPE_GAUGE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_lid", "");
+  if (ib_read_value_file(device, port, "lid_mask_count", DS_TYPE_GAUGE,
+                         &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_lid_mask_count", "");
+  if (ib_read_value_file(device, port, "sm_lid", DS_TYPE_GAUGE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_sm_lid", "");
+  if (ib_read_value_file(device, port, "sm_sl", DS_TYPE_GAUGE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_sm_sl", "");
+
+  /* PortCounters */
+
+  // Total number of data octets, divided by 4, received on all VLs at the port
+  if ((ib_read_value_file(device, port, "counters/port_rcv_data",
+                          DS_TYPE_DERIVE, &values[0]) == 0) &&
+      (ib_read_value_file(device, port, "counters/port_xmit_data",
+                          DS_TYPE_DERIVE, &values[1]) == 0)) {
+    values[0].derive *= 4;
+    values[1].derive *= 4;
+    ib_submit(device, port, values, 2, "ib_octets", "");
+  }
+  // Total number of packets, including packets containing errors, and excluding
+  //    link packets, received from all VLs on the port
+  if ((ib_read_value_file(device, port, "counters/port_rcv_packets",
+                          DS_TYPE_DERIVE, &values[0]) == 0) &&
+      (ib_read_value_file(device, port, "counters/port_xmit_packets",
+                          DS_TYPE_DERIVE, &values[1]) == 0))
+    ib_submit(device, port, values, 2, "ib_packets", "total");
+  // Total number of packets containing an error that were received on the port
+  if (ib_read_value_file(device, port, "counters/port_rcv_errors",
+                         DS_TYPE_DERIVE, &values[0]) == 0) {
+    values[1].derive = 0;
+    ib_submit(device, port, values, 2, "ib_packets", "errors");
+  }
+  // Total number of packets marked with the EBP delimiter received on the port.
+  if (ib_read_value_file(device, port,
+                         "counters/port_rcv_remote_physical_errors",
+                         DS_TYPE_DERIVE, &values[0]) == 0) {
+    values[1].derive = 0;
+    ib_submit(device, port, values, 2, "ib_packets", "remote_physical_errors");
+  }
+  // Total number of packets received on the port that were discarded because
+  //    they could not be forwarded by the switch relay
+  if (ib_read_value_file(device, port, "counters/port_rcv_switch_relay_errors",
+                         DS_TYPE_DERIVE, &values[0]) == 0) {
+    values[1].derive = 0;
+    ib_submit(device, port, values, 2, "ib_packets", "switch_relay_errors");
+  }
+  // Total number of outbound packets discarded by the port because the port is
+  //    down or congested.
+  if (ib_read_value_file(device, port, "counters/port_xmit_discards",
+                         DS_TYPE_DERIVE, &values[1]) == 0) {
+    values[0].derive = 0;
+    ib_submit(device, port, values, 2, "ib_packets", "discards");
+  }
+  // Total number of packets not transmitted from the switch physical port
+  // Total number of packets received on the switch physical port that are
+  //    discarded
+  if ((ib_read_value_file(device, port, "counters/port_rcv_constraint_errors",
+                          DS_TYPE_DERIVE, &values[0]) == 0) &&
+      (ib_read_value_file(device, port, "counters/port_xmit_constraint_errors",
+                          DS_TYPE_DERIVE, &values[1]) == 0))
+    ib_submit(device, port, values, 2, "ib_packets", "constraint_errors");
+  // Number of incoming VL15 packets dropped due to resource limitations (e.g.,
+  //    lack of buffers) in the port
+  if (ib_read_value_file(device, port, "counters/VL15_dropped", DS_TYPE_DERIVE,
+                         &values[0]) == 0) {
+    values[1].derive = 0;
+    ib_submit(device, port, values, 2, "ib_packets", "vl15_dropped");
+  }
+  // Total number of times the Port Training state machine has successfully
+  //    completed the link error recovery process.
+  if (ib_read_value_file(device, port, "counters/link_error_recovery",
+                         DS_TYPE_DERIVE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_link_error_recovery", "recovered");
+  // Total number of times the Port Training state machine has failed the link
+  //    error recovery process and downed the link.
+  if (ib_read_value_file(device, port, "counters/link_downed", DS_TYPE_DERIVE,
+                         &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_link_error_recovery", "downed");
+  // Total number of minor link errors detected on one or more physical lanes.
+  if (ib_read_value_file(device, port, "counters/symbol_error", DS_TYPE_DERIVE,
+                         &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_errors", "symbol_errors");
+  // The number of times that the count of local physical errors exceeded the
+  //    threshold specified by LocalPhyErrors
+  if (ib_read_value_file(device, port, "counters/local_link_integrity_errors",
+                         DS_TYPE_DERIVE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_errors",
+              "local_link_integrity_errors");
+  // The number of times that OverrunErrors consecutive flow control update
+  //    periods occurred, each having at least one overrun error
+  if (ib_read_value_file(device, port,
+                         "counters/excessive_buffer_overrun_errors",
+                         DS_TYPE_DERIVE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_errors",
+              "excessive_buffer_overrun_errors");
+  // The number of ticks during which the port selected by PortSelect had data
+  //    to transmit but no data was sent during the entire tick
+  if (ib_read_value_file(device, port, "counters/port_xmit_wait",
+                         DS_TYPE_DERIVE, &value) == 0)
+    ib_submit(device, port, &value, 1, "ib_xmit_wait", "");
+
+  /* PortCountersExtended */
+
+  if ((ib_read_value_file(device, port, "counters/unicast_rcv_packets",
+                          DS_TYPE_DERIVE, &values[0]) == 0) &&
+      (ib_read_value_file(device, port, "counters/unicast_xmit_packets",
+                          DS_TYPE_DERIVE, &values[1]) == 0))
+    ib_submit(device, port, values, 2, "ib_packets", "unicast");
+  if ((ib_read_value_file(device, port, "counters/multicast_rcv_packets",
+                          DS_TYPE_DERIVE, &values[0]) == 0) &&
+      (ib_read_value_file(device, port, "counters/multicast_xmit_packets",
+                          DS_TYPE_DERIVE, &values[1]) == 0))
+    ib_submit(device, port, values, 2, "ib_packets", "multicast");
+
+  return 0;
+}
+
+/* Plugin entrypoints ********************************************************/
+
+static int infiniband_config(const char *key, const char *value) {
+  if (ignorelist == NULL)
+    ignorelist = ignorelist_create(1);
+
+  if (strcasecmp(key, "Port") == 0) {
+    ignorelist_add(ignorelist, value);
+  } else if (strcasecmp(key, "IgnoreSelected") == 0) {
+    int invert = 1;
+    if (IS_TRUE(value))
+      invert = 0;
+    ignorelist_set_invert(ignorelist, invert);
+  } else {
+    return -1;
+  }
+  return 0;
+}
+
+static int infiniband_init(void) {
+  glob_t g;
+
+  if (ib_glob_ports(&g) != 0)
+    plugin_unregister_read("infiniband"); // no ports found
+
+  globfree(&g);
+  return 0;
+}
+
+static int infiniband_read(void) {
+  int rc = 0;
+  glob_t g;
+  char port_name[255];
+
+  if (ib_glob_ports(&g) == 0) {
+    for (int i = 0; i < g.gl_pathc; ++i) {
+      char *device = NULL, *port = NULL;
+      if (ib_parse_glob_port(g.gl_pathv[i], &device, &port) == 0) {
+        snprintf(port_name, sizeof(port_name), "%s:%s", device, port);
+        if (ignorelist_match(ignorelist, port_name) == 0)
+          rc &= ib_read_port(device, port);
+      }
+    }
+  }
+
+  globfree(&g);
+  return rc;
+}
+
+void module_register(void) {
+  plugin_register_config("infiniband", infiniband_config, config_keys,
+                         config_keys_num);
+  plugin_register_init("infiniband", infiniband_init);
+  plugin_register_read("infiniband", infiniband_read);
+}
index c41c22e63a1ce8193095ff983de9e6604580ee40..6bae7230819a98c242ce796d23b3515c1996bfe7 100644 (file)
@@ -114,6 +114,19 @@ http_request_methods    value:DERIVE:0:U
 http_requests           value:DERIVE:0:U
 http_response_codes     value:DERIVE:0:U
 humidity                value:GAUGE:0:100
+ib_cap_mask             value:GAUGE:0:U
+ib_errors               value:DERIVE:0:U
+ib_lid                  value:GAUGE:0:U
+ib_lid_mask_count       value:GAUGE:0:U
+ib_link_error_recovery  value:DERIVE:0:U
+ib_octets               rx:DERIVE:0:U tx:DERIVE:0:U
+ib_packets              rx:DERIVE:0:U tx:DERIVE:0:U
+ib_phys_state           value:GAUGE:0:255
+ib_rate                 value:GAUGE:0:U
+ib_sm_lid               value:GAUGE:0:U
+ib_sm_sl                value:GAUGE:0:U
+ib_state                value:GAUGE:0:255
+ib_xmit_wait            value:DERIVE:0:U
 if_collisions           value:DERIVE:0:U
 if_dropped              rx:DERIVE:0:U, tx:DERIVE:0:U
 if_errors               rx:DERIVE:0:U, tx:DERIVE:0:U