From: Asaf Kahlon Date: Sat, 12 Oct 2019 18:20:11 +0000 (+0300) Subject: buddyinfo plugin: new plugin for memory fragmentation info X-Git-Tag: collectd-5.11.0~42^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb19ecf90d89a79836b8b5236d2b66277dd79c5f;p=thirdparty%2Fcollectd.git buddyinfo plugin: new plugin for memory fragmentation info Signed-off-by: Asaf Kahlon --- diff --git a/AUTHORS b/AUTHORS index d8548d1b4..ef4ca5d04 100644 --- a/AUTHORS +++ b/AUTHORS @@ -70,7 +70,7 @@ Aneesh Puttur Andy Smith - AMQP 1.0 plugin. - + Aneesh Puttur - connectivity plugin. @@ -83,6 +83,9 @@ Anthony Gialluca Antony Dovgal - memcached plugin. +Asaf Kahlon + - buddyinfo plugin + Aurélien Reynaud - LPAR plugin. - Various fixes for AIX, HP-UX and Solaris. diff --git a/Makefile.am b/Makefile.am index bdb95a1b3..169f85ca8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -746,6 +746,13 @@ bind_la_LDFLAGS = $(PLUGIN_LDFLAGS) bind_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBXML2_LIBS) endif +if BUILD_PLUGIN_BUDDYINFO +pkglib_LTLIBRARIES += buddyinfo.la +buddyinfo_la_SOURCES = src/buddyinfo.c +buddyinfo_la_LDFLAGS = $(PLUGIN_LDFLAGS) +buddyinfo_la_LIBADD = libignorelist.la +endif + if BUILD_PLUGIN_CEPH pkglib_LTLIBRARIES += ceph.la ceph_la_SOURCES = src/ceph.c diff --git a/README b/README index f77efd219..017cb51e1 100644 --- a/README +++ b/README @@ -45,6 +45,9 @@ Features Name server and resolver statistics from the `statistics-channel' interface of BIND 9.5, 9,6 and later. + - buddyinfo + Statistics from buddyinfo file about memory fragmentation. + - ceph Statistics from the Ceph distributed storage system. diff --git a/configure.ac b/configure.ac index 4e585bd21..631616bb1 100644 --- a/configure.ac +++ b/configure.ac @@ -6371,6 +6371,7 @@ plugin_ascent="no" plugin_barometer="no" plugin_battery="no" plugin_bind="no" +plugin_buddyinfo="no" plugin_ceph="no" plugin_cgroups="no" plugin_connectivity="no" @@ -6443,6 +6444,7 @@ plugin_zookeeper="no" # Linux if test "x$ac_system" = "xLinux"; then plugin_battery="yes" + plugin_buddyinfo="yes" plugin_cgroups="yes" plugin_conntrack="yes" plugin_contextswitch="yes" @@ -6803,6 +6805,7 @@ AC_PLUGIN([ascent], [$plugin_ascent], [AscentEmu player AC_PLUGIN([barometer], [$plugin_barometer], [Barometer sensor on I2C]) AC_PLUGIN([battery], [$plugin_battery], [Battery statistics]) AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics]) +AC_PLUGIN([buddyinfo], [$plugin_buddyinfo], [buddyinfo statistics]) AC_PLUGIN([ceph], [$plugin_ceph], [Ceph daemon statistics]) AC_PLUGIN([cgroups], [$plugin_cgroups], [CGroups CPU usage accounting]) AC_PLUGIN([chrony], [yes], [Chrony statistics]) @@ -7236,6 +7239,7 @@ AC_MSG_RESULT([ ascent . . . . . . . $enable_ascent]) AC_MSG_RESULT([ barometer . . . . . . $enable_barometer]) AC_MSG_RESULT([ battery . . . . . . . $enable_battery]) AC_MSG_RESULT([ bind . . . . . . . . $enable_bind]) +AC_MSG_RESULT([ buddyinfo . . . . . . $enable_buddyinfo]) AC_MSG_RESULT([ ceph . . . . . . . . $enable_ceph]) AC_MSG_RESULT([ cgroups . . . . . . . $enable_cgroups]) AC_MSG_RESULT([ chrony. . . . . . . . $enable_chrony]) diff --git a/src/buddyinfo.c b/src/buddyinfo.c new file mode 100644 index 000000000..5b0de5278 --- /dev/null +++ b/src/buddyinfo.c @@ -0,0 +1,110 @@ +/** + * collectd - src/buddyinfo.c + * Copyright (C) 2005-2010 Florian octo Forster + * Copyright (C) 2009 Manuel Sanmartin + * + * 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 + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Asaf Kahlon + **/ + +#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 + +#define MAX_ORDER 11 +#define BUDDYINFO_FIELDS MAX_ORDER + 2 // "zone" + Name + (MAX_ORDER entries) +#define NUM_OF_KB(pagesize, order) ((pagesize) / 1024) * (1 << (order)) + +static const char *config_keys[] = {"Zone"}; +static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); + +static ignorelist_t *ignorelist; + +static int buddyinfo_config(const char *key, const char *value) { + if (ignorelist == NULL) + ignorelist = ignorelist_create(1); + + if (strcasecmp(key, "Zone") == 0) + ignorelist_add(ignorelist, value); + else + return -1; + + return 0; +} + +static void buddyinfo_submit(const char *zone, const char *size, + const int freepages) { + value_list_t vl = VALUE_LIST_INIT; + value_t value = {.gauge = freepages}; + + if (ignorelist_match(ignorelist, zone) != 0) + return; + + vl.values = &value; + vl.values_len = 1; + sstrncpy(vl.plugin, "buddyinfo", sizeof(vl.plugin)); + sstrncpy(vl.plugin_instance, zone, sizeof(vl.plugin_instance)); + sstrncpy(vl.type, "freepages", sizeof(vl.type)); + sstrncpy(vl.type_instance, size, sizeof(vl.type_instance)); + + plugin_dispatch_values(&vl); +} + +static int buddyinfo_read(void) { + FILE *fh; + char buffer[1024], pagesize_kb[8]; + char *dummy, *zone; + char *fields[BUDDYINFO_FIELDS]; + int numfields, pagesize = getpagesize(); + + if ((fh = fopen("/proc/buddyinfo", "r")) == NULL) { + WARNING("buddyinfo plugin: fopen: %s", STRERRNO); + return -1; + } + + while (fgets(buffer, sizeof(buffer), fh) != NULL) { + if (!(dummy = strstr(buffer, "zone"))) + continue; + + numfields = strsplit(dummy, fields, BUDDYINFO_FIELDS); + if (numfields != BUDDYINFO_FIELDS) + continue; + + zone = fields[1]; + for (int i = 1; i <= MAX_ORDER; i++) { + ssnprintf(pagesize_kb, sizeof(pagesize_kb), "%dKB", + NUM_OF_KB(pagesize, i - 1)); + buddyinfo_submit(zone, pagesize_kb, atoll(fields[i + 1])); + } + } + + fclose(fh); + return 0; +} + +void module_register(void) { + plugin_register_config("buddyinfo", buddyinfo_config, config_keys, + config_keys_num); + plugin_register_read("buddyinfo", buddyinfo_read); +} diff --git a/src/collectd.conf.in b/src/collectd.conf.in index a194b4752..cbfc3a329 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -99,6 +99,7 @@ #@BUILD_PLUGIN_BAROMETER_TRUE@LoadPlugin barometer #@BUILD_PLUGIN_BATTERY_TRUE@LoadPlugin battery #@BUILD_PLUGIN_BIND_TRUE@LoadPlugin bind +#@BUILD_PLUGIN_BUDDYINFO_TRUE@LoadPlugin buddyinfo #@BUILD_PLUGIN_CEPH_TRUE@LoadPlugin ceph #@BUILD_PLUGIN_CGROUPS_TRUE@LoadPlugin cgroups #@BUILD_PLUGIN_CHRONY_TRUE@LoadPlugin chrony @@ -363,6 +364,10 @@ # # +# +# Zone "Normal" +# + # # LongRunAvgLatency false # ConvertSpecialMetricTypes true @@ -1280,7 +1285,7 @@ # # BufferLength 10 -# ProcessRegex "/^ovs.*$/" +# ProcessRegex "/^ovs.*$/" # Process tuned # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index cda1002c5..f7a5b1126 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1455,6 +1455,20 @@ By default no detailed zone information is collected. =back +=head2 Plugin C + +The B plugin collects information by reading "/proc/buddyinfo". +This file contains information about the number of available contagious +physical pages at the moment. + +=over 4 + +=item B I + +Zone to collect info about. Will collect all zones by default. + +=back + =head2 Plugin C The ceph plugin collects values from JSON data to be parsed by B @@ -1635,12 +1649,12 @@ LoadPlugin connectivity Interface eth1 IgnoreSelected true - + =over 4 =item B I -interface(s) to monitor connect to. +interface(s) to monitor connect to. =back @@ -5615,7 +5629,7 @@ necessary in rare cases. Set the outgoing IP address for IP packets. This option can be used instead of the I option to explicitly define the IP address which will be used -to send Packets to the remote server. +to send Packets to the remote server. =item B I @@ -7386,37 +7400,37 @@ B blocks these options set the default value for subsequent matches. =head2 Plugin C - + The I plugin monitors when processes start (EXEC) and stop (EXIT). - + B - + BufferLength 10 Process "name" ProcessRegex "regex" - + B - + =over 4 - + =item B I - + Maximum number of process events that can be stored in plugin's ring buffer. By default, this is set to 10. Once an event has been read, its location becomes available for storing a new event. - + =item B I - + Enumerate a process name to monitor. All processes that match this exact name will be monitored for EXECs and EXITs. =item B I - -Enumerate a process pattern to monitor. All processes that match this + +Enumerate a process pattern to monitor. All processes that match this regular expression will be monitored for EXECs and EXITs. - + =back =head2 Plugin C @@ -8353,11 +8367,11 @@ or is not reliable. =back =head2 Plugin C - + The I plugin monitors rsyslog messages. - + B - + Listen "192.168.0.2" "6666" BufferSize 1024 @@ -8387,33 +8401,33 @@ B *.* @192.168.0.2:6666;ls_json Please note that these rsyslog.conf examples are *not* complete, as rsyslog - requires more than these options in the configuration file. These examples + requires more than these options in the configuration file. These examples are meant to demonstration the proper remote logging and JSON format syntax. B - + =over 4 - + =item B I I - + Listen on this IP on this port for incoming rsyslog messages. =item B I - -Maximum allowed size for incoming rsyslog messages. Messages that exceed + +Maximum allowed size for incoming rsyslog messages. Messages that exceed this number will be truncated to this size. Default is 4096 bytes. =item B I - + Maximum number of rsyslog events that can be stored in plugin's ring buffer. By default, this is set to 10. Once an event has been read, its location becomes available for storing a new event. =item B I - + Enumerate a regex filter to apply to all incoming rsyslog messages. If a message matches this filter, it will be published. - + =back =head2 Plugin C @@ -8736,7 +8750,7 @@ the following schema: Bucket 20 50 Bucket 50 0 -Metrics are reported with the I set by B option (C +Metrics are reported with the I set by B option (C by default) and the I CTypeE[-EInstanceE]-Elower_boundE_Eupper_boundE>. diff --git a/src/types.db b/src/types.db index 6c08936e9..7face74d1 100644 --- a/src/types.db +++ b/src/types.db @@ -97,6 +97,7 @@ files value:GAUGE:0:U filter_result value:DERIVE:0:U flow value:GAUGE:0:U fork_rate value:DERIVE:0:U +freepages value:GAUGE:0:U frequency value:GAUGE:0:U frequency_error value:GAUGE:-1000000:1000000 frequency_offset value:GAUGE:-1000000:1000000