From 95e95817de3f4962bf87fa1848c483fa27a02a0f Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 22 Jul 2009 15:57:47 +0200 Subject: [PATCH] match_empty_counter plugin: Match for zero counter values. --- README | 3 ++ configure.in | 2 + src/Makefile.am | 8 ++++ src/collectd.conf.pod | 13 +++++ src/match_empty_counter.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 src/match_empty_counter.c diff --git a/README b/README index 83eede28..1cfa6434 100644 --- a/README +++ b/README @@ -340,6 +340,9 @@ Features * Value processing can be controlled using the "filter chain" infrastructure and "matches" and "targets". The following plugins are available: + - match_empty_counter + Match counter values which are currently zero. + - match_regex Match values by their identifier based on regular expressions. diff --git a/configure.in b/configure.in index 4ef308e2..65e296a8 100644 --- a/configure.in +++ b/configure.in @@ -3717,6 +3717,7 @@ AC_PLUGIN([java], [$with_java], [Embed the Java Virtual Machine]) AC_PLUGIN([libvirt], [$plugin_libvirt], [Virtual machine statistics]) AC_PLUGIN([load], [$plugin_load], [System load]) AC_PLUGIN([logfile], [yes], [File logging plugin]) +AC_PLUGIN([match_empty_counter], [yes], [The empty counter match]) AC_PLUGIN([match_regex], [yes], [The regex match]) AC_PLUGIN([match_timediff], [yes], [The timediff match]) AC_PLUGIN([match_value], [yes], [The value match]) @@ -4013,6 +4014,7 @@ Configuration: libvirt . . . . . . . $enable_libvirt load . . . . . . . . $enable_load logfile . . . . . . . $enable_logfile + match_empty_counter . $enable_match_empty_counter match_regex . . . . . $enable_match_regex match_timediff . . . $enable_match_timediff match_value . . . . . $enable_match_value diff --git a/src/Makefile.am b/src/Makefile.am index e6d9073c..d7d92c48 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -453,6 +453,14 @@ collectd_LDADD += "-dlopen" logfile.la collectd_DEPENDENCIES += logfile.la endif +if BUILD_PLUGIN_MATCH_EMPTY_COUNTER +pkglib_LTLIBRARIES += match_empty_counter.la +match_empty_counter_la_SOURCES = match_empty_counter.c +match_empty_counter_la_LDFLAGS = -module -avoid-version +collectd_LDADD += "-dlopen" match_empty_counter.la +collectd_DEPENDENCIES += match_empty_counter.la +endif + if BUILD_PLUGIN_MATCH_REGEX pkglib_LTLIBRARIES += match_regex.la match_regex_la_SOURCES = match_regex.c diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index e401d42a..8a5f6fde 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -4057,6 +4057,19 @@ Example: Satisfy "Any" +=item B + +Matches all values with one or more data sources of type B and where +all counter values are zero. These counters usually I increased since +they started existing (and are therefore uninteresting), or got reset recently +or overflowed and you had really, I bad luck. + +Please keep in mind that ignoring such counters can result in confusing +behavior: Counters which hardly ever increase will be zero for long periods of +time. If the counter is reset for some reason (machine or service restarted, +usually), the graph will be empty (NAN) for a long time. People may not +understand why. + =back =head2 Available targets diff --git a/src/match_empty_counter.c b/src/match_empty_counter.c new file mode 100644 index 00000000..b9afd817 --- /dev/null +++ b/src/match_empty_counter.c @@ -0,0 +1,118 @@ +/** + * collectd - src/match_empty_counter.c + * Copyright (C) 2009 Florian Forster + * + * 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: + * Florian Forster + **/ + +#include "collectd.h" +#include "common.h" +#include "utils_cache.h" +#include "filter_chain.h" + +/* + * private data types + */ +struct mec_match_s; +typedef struct mec_match_s mec_match_t; +struct mec_match_s +{ + int dummy; +}; + +/* + * internal helper functions + */ +static int mec_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ +{ + mec_match_t *m; + + m = (mec_match_t *) malloc (sizeof (*m)); + if (m == NULL) + { + ERROR ("mec_create: malloc failed."); + return (-ENOMEM); + } + memset (m, 0, sizeof (*m)); + + if (ci->children_num != 0) + { + ERROR ("empty_counter match: This match does not take any additional " + "configuration."); + } + + *user_data = m; + return (0); +} /* }}} int mec_create */ + +static int mec_destroy (void **user_data) /* {{{ */ +{ + if (user_data != NULL) + { + sfree (*user_data); + } + + return (0); +} /* }}} int mec_destroy */ + +static int mec_match (const data_set_t __attribute__((unused)) *ds, /* {{{ */ + const value_list_t *vl, + notification_meta_t __attribute__((unused)) **meta, void **user_data) +{ + mec_match_t *m; + int num_counters; + int num_empty; + int i; + + if ((user_data == NULL) || (*user_data == NULL)) + return (-1); + + m = *user_data; + + num_counters = 0; + num_empty = 0; + + for (i = 0; i < ds->ds_num; i++) + { + if (ds->ds[i].type != DS_TYPE_COUNTER) + continue; + + num_counters++; + if (vl->values[i].counter == 0) + num_empty++; + } + + if (num_counters == 0) + return (FC_MATCH_NO_MATCH); + else if (num_counters == num_empty) + return (FC_MATCH_MATCHES); + else + return (FC_MATCH_NO_MATCH); +} /* }}} int mec_match */ + +void module_register (void) +{ + match_proc_t mproc; + + memset (&mproc, 0, sizeof (mproc)); + mproc.create = mec_create; + mproc.destroy = mec_destroy; + mproc.match = mec_match; + fc_register_match ("empty_counter", mproc); +} /* module_register */ + +/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */ -- 2.11.0