From 171a92c968cb41c314736b0d26f5a6ba2ae59666 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 5 Dec 2010 11:05:43 +0100 Subject: [PATCH] threshold plugin: Move the threshold checking code into a plugin. --- README | 4 + configure.in | 2 + src/Makefile.am | 12 +- src/collectd-threshold.pod | 194 +++++++++++++++++++++++++ src/collectd.conf.in | 49 +++++++ src/collectd.conf.pod | 179 ++--------------------- src/configfile.c | 3 - src/plugin.c | 4 - src/{utils_threshold.c => threshold.c} | 251 ++++++++++++++------------------- src/utils_cache.c | 35 ----- src/utils_threshold.h | 87 ------------ 11 files changed, 376 insertions(+), 444 deletions(-) create mode 100644 src/collectd-threshold.pod rename src/{utils_threshold.c => threshold.c} (89%) delete mode 100644 src/utils_threshold.h diff --git a/README b/README index 2ed8934f..e8b7241b 100644 --- a/README +++ b/README @@ -442,6 +442,10 @@ Features * Miscellaneous plugins: + - threshold + Checks values against configured thresholds and creates notifications if + values are out of bounds. See collectd-threshold(5) for details. + - uuid Sets the hostname to an unique identifier. This is meant for setups where each client may migrate to another physical host, possibly going diff --git a/configure.in b/configure.in index 3b46188a..8ec84155 100644 --- a/configure.in +++ b/configure.in @@ -4637,6 +4637,7 @@ AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics]) AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics]) AC_PLUGIN([ted], [$plugin_ted], [Read The Energy Detective values]) AC_PLUGIN([thermal], [$plugin_thermal], [Linux ACPI thermal zone statistics]) +AC_PLUGIN([threshold], [yes], [Threshold checking plugin]) AC_PLUGIN([tokyotyrant], [$with_libtokyotyrant], [TokyoTyrant database statistics]) AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin]) AC_PLUGIN([uptime], [$plugin_uptime], [Uptime statistics]) @@ -4962,6 +4963,7 @@ Configuration: teamspeak2 . . . . . $enable_teamspeak2 ted . . . . . . . . . $enable_ted thermal . . . . . . . $enable_thermal + threshold . . . . . . $enable_threshold tokyotyrant . . . . . $enable_tokyotyrant unixsock . . . . . . $enable_unixsock uptime . . . . . . . $enable_uptime diff --git a/src/Makefile.am b/src/Makefile.am index 1a7ba5b1..57281440 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,7 +40,6 @@ collectd_SOURCES = collectd.c collectd.h \ utils_match.c utils_match.h \ utils_subst.c utils_subst.h \ utils_tail.c utils_tail.h \ - utils_threshold.c utils_threshold.h \ utils_time.c utils_time.h \ types_list.c types_list.h @@ -1131,6 +1130,14 @@ collectd_LDADD += "-dlopen" thermal.la collectd_DEPENDENCIES += thermal.la endif +if BUILD_PLUGIN_THRESHOLD +pkglib_LTLIBRARIES += threshold.la +threshold_la_SOURCES = threshold.c +threshold_la_LDFLAGS = -module -avoid-version +collectd_LDADD += "-dlopen" threshold.la +collectd_DEPENDENCIES += threshold.la +endif + if BUILD_PLUGIN_TOKYOTYRANT pkglib_LTLIBRARIES += tokyotyrant.la tokyotyrant_la_SOURCES = tokyotyrant.c @@ -1149,7 +1156,6 @@ pkglib_LTLIBRARIES += unixsock.la unixsock_la_SOURCES = unixsock.c \ utils_cmd_flush.h utils_cmd_flush.c \ utils_cmd_getval.h utils_cmd_getval.c \ - utils_cmd_getthreshold.h utils_cmd_getthreshold.c \ utils_cmd_listval.h utils_cmd_listval.c \ utils_cmd_putval.h utils_cmd_putval.c \ utils_cmd_putnotif.h utils_cmd_putnotif.c @@ -1286,6 +1292,7 @@ dist_man_MANS = collectd.1 \ collectd-perl.5 \ collectd-python.5 \ collectd-snmp.5 \ + collectd-threshold.5 \ collectd-unixsock.5 \ types.db.5 @@ -1304,6 +1311,7 @@ EXTRA_DIST += collectd.conf.pod \ collectd-python.pod \ collectd.pod \ collectd-snmp.pod \ + collectd-threshold.pod \ collectd-unixsock.pod \ postgresql_default.conf \ types.db.pod diff --git a/src/collectd-threshold.pod b/src/collectd-threshold.pod new file mode 100644 index 00000000..5d1a645c --- /dev/null +++ b/src/collectd-threshold.pod @@ -0,0 +1,194 @@ +=head1 NAME + +collectd-threshold - Documentation of collectd's I + +=head1 SYNOPSIS + + LoadPlugin "threshold" + + + WarningMin 0.00 + WarningMax 1000.00 + FailureMin 0.00 + FailureMax 1200.00 + Invert false + Instance "bar" + + + +=head1 DESCRIPTION + +Starting with version C<4.3.0> I has support for B. By +that we mean that the values are not only stored or sent somewhere, but that +they are judged and, if a problem is recognized, acted upon. The only action +the I takes itself is to generate and dispatch a +I. Other plugins can register to receive notifications and +perform appropriate further actions. + +Since systems and what you expect them to do differ a lot, you can configure +I for your values freely. This gives you a lot of flexibility but +also a lot of responsibility. + +Every time a value is out of range, a notification is dispatched. This means +that the idle percentage of your CPU needs to be less then the configured +threshold only once for a notification to be generated. There's no such thing +as a moving average or similar - at least not now. + +Also, all values that match a threshold are considered to be relevant or +"interesting". As a consequence collectd will issue a notification if they are +not received for B iterations. The B configuration option is +explained in section L. If, for example, +B is set to "2" (the default) and some hosts sends it's CPU statistics +to the server every 60 seconds, a notification will be dispatched after about +120 seconds. It may take a little longer because the timeout is checked only +once each B on the server. + +When a value comes within range again or is received after it was missing, an +"OKAY-notification" is dispatched. + +=head1 CONFIGURATION + +Here is a configuration example to get you started. Read below for more +information. + + LoadPlugin "threshold" + + + WarningMin 0.00 + WarningMax 1000.00 + FailureMin 0.00 + FailureMax 1200.00 + Invert false + Instance "bar" + + + + Instance "eth0" + + FailureMax 10000000 + DataSource "rx" + + + + + + Instance "idle" + FailureMin 10 + + + + + Instance "cached" + WarningMin 100000000 + + + + + DataSource "midterm" + FailureMax 4 + Hits 3 + Hysteresis 3 + + + + +There are basically two types of configuration statements: The C, +C, and C blocks select the value for which a threshold should be +configured. The C and C blocks may be specified further using the +C option. You can combine the block by nesting the blocks, though +they must be nested in the above order, i.e. C may contain either +C and C blocks, C may only contain C blocks and +C may not contain other blocks. If multiple blocks apply to the same +value the most specific block is used. + +The other statements specify the threshold to configure. They B be +included in a C block. Currently the following statements are recognized: + +=over 4 + +=item B I + +=item B I + +Sets the upper bound of acceptable values. If unset defaults to positive +infinity. If a value is greater than B a B notification +will be created. If the value is greater than B but less than (or +equal to) B a B notification will be created. + +=item B I + +=item B I + +Sets the lower bound of acceptable values. If unset defaults to negative +infinity. If a value is less than B a B notification will +be created. If the value is less than B but greater than (or equal +to) B a B notification will be created. + +=item B I + +Some data sets have more than one "data source". Interesting examples are the +C data set, which has received (C) and sent (C) bytes and +the C data set, which holds C and C operations. The +system load data set, C, even has three data sources: C, +C, and C. + +Normally, all data sources are checked against a configured threshold. If this +is undesirable, or if you want to specify different limits for each data +source, you can use the B option to have a threshold apply only to +one data source. + +=item B B|B + +If set to B the range of acceptable values is inverted, i.e. values +between B and B (B and B) are +not okay. Defaults to B. + +=item B B|B + +Sets how often notifications are generated. If set to B one notification +will be generated for each value that is out of the acceptable range. If set to +B (the default) then a notification is only generated if a value is out +of range but the previous value was okay. + +This applies to missing values, too: If set to B a notification about a +missing value is generated once every B seconds. If set to B +only one such notification is generated until the value appears again. + +=item B B|B + +If set to B, the minimum and maximum values given are interpreted as +percentage value, relative to the other data sources. This is helpful for +example for the "df" type, where you may want to issue a warning when less than +5E% of the total space is available. Defaults to B. + +=item B I + +Sets the number of occurrences which the threshold must be raised before to +dispatch any notification or, in other words, the number of Bs +that the threshold must be match before dispatch any notification. + +=item B I + +Sets the hysteresis value for threshold. The hysteresis is a method to prevent +flapping between states, until a new received value for a previously matched +threshold down below the threshold condition (B, B or +everything else) minus the hysteresis value, the failure (respectively warning) +state will be keep. + +=item B B|B + +If set to B (the default), the threshold must be treated as interesting +and, when a number of B values will lost, then a missing notification +will be dispatched. On the other hand, if set to B, the missing +notification will never dispatched for this threshold. + +=back + +=head1 SEE ALSO + +L, +L + +=head1 AUTHOR + +Florian Forster EoctoEatEcollectd.orgE diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 12259098..32a7582c 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1000,3 +1000,52 @@ # # Target "write" # + +############################################################################## +# Threshold configuration # +#----------------------------------------------------------------------------# +# The following outlines how to configure collectd's threshold checking # +# plugin. The plugin and possible configuration options are documented in # +# the collectd-threshold(5) manual page. # +############################################################################## + +#@BUILD_PLUGIN_THRESHOLD_TRUE@LoadPlugin "threshold" +# +# +# WarningMin 0.00 +# WarningMax 1000.00 +# FailureMin 0.00 +# FailureMax 1200.00 +# Invert false +# Instance "bar" +# +# +# +# Instance "eth0" +# +# FailureMax 10000000 +# DataSource "rx" +# +# +# +# +# +# Instance "idle" +# FailureMin 10 +# +# +# +# +# Instance "cached" +# WarningMin 100000000 +# +# +# +# +# DataSource "midterm" +# FailureMax 4 +# Hits 3 +# Hysteresis 3 +# +# +# diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index c1c9a253..acdfa927 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -141,7 +141,7 @@ missing when no update has been received for twice the update interval. Since this setting uses iterations, the maximum allowed time without update depends on the I information contained in each value list. This is used in the I configuration to dispatch notifications about missing values, -see L<"THRESHOLD CONFIGURATION"> below. +see L for details. =item B I @@ -4530,7 +4530,7 @@ port in numeric form. =item B I|I -By default, the C plugin tries to read the statistics from the Linux +By default, the I tries to read the statistics from the Linux C interface. If that is not available, the plugin falls back to the C interface. By setting this option to I, you can force the plugin to use the latter. This option defaults to I. @@ -4550,9 +4550,18 @@ selection is configured at all, B devices are selected. =back +=head2 Plugin C + +The I checks values collected or received by I +against a configurable I and issues I if values are +out of bounds. + +Documentation for this plugin is available in the L +manual page. + =head2 Plugin C -The C connects to a TokyoTyrant server and collects a +The I connects to a TokyoTyrant server and collects a couple metrics: number of records, and database size on disk. =over 4 @@ -4799,170 +4808,6 @@ number. =back -=head1 THRESHOLD CONFIGURATION - -Starting with version C<4.3.0> collectd has support for B. By that -we mean that the values are not only stored or sent somewhere, but that they -are judged and, if a problem is recognized, acted upon. The only action -collectd takes itself is to generate and dispatch a "notification". Plugins can -register to receive notifications and perform appropriate further actions. - -Since systems and what you expect them to do differ a lot, you can configure -B for your values freely. This gives you a lot of flexibility but -also a lot of responsibility. - -Every time a value is out of range a notification is dispatched. This means -that the idle percentage of your CPU needs to be less then the configured -threshold only once for a notification to be generated. There's no such thing -as a moving average or similar - at least not now. - -Also, all values that match a threshold are considered to be relevant or -"interesting". As a consequence collectd will issue a notification if they are -not received for B iterations. The B configuration option is -explained in section L<"GLOBAL OPTIONS">. If, for example, B is set to -"2" (the default) and some hosts sends it's CPU statistics to the server every -60 seconds, a notification will be dispatched after about 120 seconds. It may -take a little longer because the timeout is checked only once each B -on the server. - -When a value comes within range again or is received after it was missing, an -"OKAY-notification" is dispatched. - -Here is a configuration example to get you started. Read below for more -information. - - - - WarningMin 0.00 - WarningMax 1000.00 - FailureMin 0.00 - FailureMax 1200.00 - Invert false - Instance "bar" - - - - Instance "eth0" - - FailureMax 10000000 - DataSource "rx" - - - - - - Instance "idle" - FailureMin 10 - - - - - Instance "cached" - WarningMin 100000000 - - - - - DataSource "midterm" - FailureMax 4 - Hits 3 - Hysteresis 3 - - - - -There are basically two types of configuration statements: The C, -C, and C blocks select the value for which a threshold should be -configured. The C and C blocks may be specified further using the -C option. You can combine the block by nesting the blocks, though -they must be nested in the above order, i.Ee. C may contain either -C and C blocks, C may only contain C blocks and -C may not contain other blocks. If multiple blocks apply to the same -value the most specific block is used. - -The other statements specify the threshold to configure. They B be -included in a C block. Currently the following statements are recognized: - -=over 4 - -=item B I - -=item B I - -Sets the upper bound of acceptable values. If unset defaults to positive -infinity. If a value is greater than B a B notification -will be created. If the value is greater than B but less than (or -equal to) B a B notification will be created. - -=item B I - -=item B I - -Sets the lower bound of acceptable values. If unset defaults to negative -infinity. If a value is less than B a B notification will -be created. If the value is less than B but greater than (or equal -to) B a B notification will be created. - -=item B I - -Some data sets have more than one "data source". Interesting examples are the -C data set, which has received (C) and sent (C) bytes and -the C data set, which holds C and C operations. The -system load data set, C, even has three data sources: C, -C, and C. - -Normally, all data sources are checked against a configured threshold. If this -is undesirable, or if you want to specify different limits for each data -source, you can use the B option to have a threshold apply only to -one data source. - -=item B B|B - -If set to B the range of acceptable values is inverted, i.Ee. -values between B and B (B and -B) are not okay. Defaults to B. - -=item B B|B - -Sets how often notifications are generated. If set to B one notification -will be generated for each value that is out of the acceptable range. If set to -B (the default) then a notification is only generated if a value is out -of range but the previous value was okay. - -This applies to missing values, too: If set to B a notification about a -missing value is generated once every B seconds. If set to B -only one such notification is generated until the value appears again. - -=item B B|B - -If set to B, the minimum and maximum values given are interpreted as -percentage value, relative to the other data sources. This is helpful for -example for the "df" type, where you may want to issue a warning when less than -5E% of the total space is available. Defaults to B. - -=item B I - -Sets the number of occurrences which the threshold must be arised before to -dispatch any notification or, in other words, the number of Bs -than the threshold must be match before dispatch any notification. - -=item B I - -Sets the hysteresis value for threshold. The hysteresis is a method to -prevent flapping between states, until a new received value for -a previously matched threshold down below the threshold condition -(B, B or everthing else) minus the hysteresis value, -the failure (respectively warning) state will be keep. - -=item B B|B - -If set to B (the default), the threshold must be treated as -interesting and, when a number of B values will lost, then -a missing notification will be dispatched. On the other hand, if set to -B, the missing notification will never dispatched for this threshold. - -=back - =head1 FILTER CONFIGURATION Starting with collectd 4.6 there is a powerful filtering infrastructure diff --git a/src/configfile.c b/src/configfile.c index e162dd99..11200f61 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -29,7 +29,6 @@ #include "plugin.h" #include "configfile.h" #include "types_list.h" -#include "utils_threshold.h" #include "filter_chain.h" #if HAVE_WORDEXP_H @@ -372,8 +371,6 @@ static int dispatch_block (oconfig_item_t *ci) return (dispatch_loadplugin (ci)); else if (strcasecmp (ci->key, "Plugin") == 0) return (dispatch_block_plugin (ci)); - else if (strcasecmp (ci->key, "Threshold") == 0) - return (ut_config (ci)); else if (strcasecmp (ci->key, "Chain") == 0) return (fc_configure (ci)); diff --git a/src/plugin.c b/src/plugin.c index e32c8f9c..a298d350 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -36,7 +36,6 @@ #include "utils_llist.h" #include "utils_heap.h" #include "utils_cache.h" -#include "utils_threshold.h" #include "filter_chain.h" /* @@ -1525,9 +1524,6 @@ int plugin_dispatch_values (value_list_t *vl) /* Update the value cache */ uc_update (ds, vl); - /* Initiate threshold checking */ - ut_check_threshold (ds, vl); - if (post_cache_chain != NULL) { status = fc_process_chain (ds, vl, post_cache_chain); diff --git a/src/utils_threshold.c b/src/threshold.c similarity index 89% rename from src/utils_threshold.c rename to src/threshold.c index 99309b93..89397502 100644 --- a/src/utils_threshold.c +++ b/src/threshold.c @@ -1,10 +1,9 @@ /** - * collectd - src/utils_threshold.c - * Copyright (C) 2007-2009 Florian octo Forster + * collectd - src/threshold.c + * Copyright (C) 2007-2010 Florian Forster * Copyright (C) 2008-2009 Sebastian Harl * Copyright (C) 2009 Andrés J. Díaz * - * * 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. @@ -19,7 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Author: - * Florian octo Forster + * Florian octo Forster * Sebastian Harl * Andrés J. Díaz **/ @@ -29,7 +28,6 @@ #include "plugin.h" #include "utils_avltree.h" #include "utils_cache.h" -#include "utils_threshold.h" #include #include @@ -41,6 +39,23 @@ #define UT_FLAG_PERSIST 0x02 #define UT_FLAG_PERCENTAGE 0x04 #define UT_FLAG_INTERESTING 0x08 +typedef struct threshold_s +{ + char host[DATA_MAX_NAME_LEN]; + char plugin[DATA_MAX_NAME_LEN]; + char plugin_instance[DATA_MAX_NAME_LEN]; + char type[DATA_MAX_NAME_LEN]; + char type_instance[DATA_MAX_NAME_LEN]; + char data_source[DATA_MAX_NAME_LEN]; + gauge_t warning_min; + gauge_t warning_max; + gauge_t failure_min; + gauge_t failure_max; + gauge_t hysteresis; + unsigned int flags; + int hits; + struct threshold_s *next; +} threshold_t; /* }}} */ /* @@ -55,11 +70,18 @@ static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER; * ==================== * The following functions add, delete, search, etc. configured thresholds to * the underlying AVL trees. - * {{{ */ + */ +/* + * threshold_t *threshold_get + * + * Retrieve one specific threshold configuration. For looking up a threshold + * matching a value_list_t, see "threshold_search" below. Returns NULL if the + * specified threshold doesn't exist. + */ static threshold_t *threshold_get (const char *hostname, const char *plugin, const char *plugin_instance, const char *type, const char *type_instance) -{ +{ /* {{{ */ char name[6 * DATA_MAX_NAME_LEN]; threshold_t *th = NULL; @@ -73,10 +95,17 @@ static threshold_t *threshold_get (const char *hostname, return (th); else return (NULL); -} /* threshold_t *threshold_get */ +} /* }}} threshold_t *threshold_get */ +/* + * int ut_threshold_add + * + * Adds a threshold configuration to the list of thresholds. The threshold_t + * structure is copied and may be destroyed after this call. Returns zero on + * success, non-zero otherwise. + */ static int ut_threshold_add (const threshold_t *th) -{ +{ /* {{{ */ char name[6 * DATA_MAX_NAME_LEN]; char *name_copy; threshold_t *th_copy; @@ -139,10 +168,59 @@ static int ut_threshold_add (const threshold_t *th) } return (status); -} /* int ut_threshold_add */ -/* - * End of the threshold management functions - * }}} */ +} /* }}} int ut_threshold_add */ + +/* + * threshold_t *threshold_search + * + * Searches for a threshold configuration using all the possible variations of + * "Host", "Plugin" and "Type" blocks. Returns NULL if no threshold could be + * found. + * XXX: This is likely the least efficient function in collectd. + */ +static threshold_t *threshold_search (const value_list_t *vl) +{ /* {{{ */ + threshold_t *th; + + if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, + vl->type, vl->type_instance)) != NULL) + return (th); + else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, + vl->type, NULL)) != NULL) + return (th); + else if ((th = threshold_get (vl->host, vl->plugin, NULL, + vl->type, vl->type_instance)) != NULL) + return (th); + else if ((th = threshold_get (vl->host, vl->plugin, NULL, + vl->type, NULL)) != NULL) + return (th); + else if ((th = threshold_get (vl->host, "", NULL, + vl->type, vl->type_instance)) != NULL) + return (th); + else if ((th = threshold_get (vl->host, "", NULL, + vl->type, NULL)) != NULL) + return (th); + else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, + vl->type, vl->type_instance)) != NULL) + return (th); + else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, + vl->type, NULL)) != NULL) + return (th); + else if ((th = threshold_get ("", vl->plugin, NULL, + vl->type, vl->type_instance)) != NULL) + return (th); + else if ((th = threshold_get ("", vl->plugin, NULL, + vl->type, NULL)) != NULL) + return (th); + else if ((th = threshold_get ("", "", NULL, + vl->type, vl->type_instance)) != NULL) + return (th); + else if ((th = threshold_get ("", "", NULL, + vl->type, NULL)) != NULL) + return (th); + + return (NULL); +} /* }}} threshold_t *threshold_search */ /* * Configuration @@ -435,7 +513,7 @@ static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci) return (status); } /* int ut_config_host */ -int ut_config (const oconfig_item_t *ci) +int ut_config (oconfig_item_t *ci) { int i; int status = 0; @@ -497,50 +575,6 @@ int ut_config (const oconfig_item_t *ci) */ /* }}} */ -static threshold_t *threshold_search (const value_list_t *vl) -{ - threshold_t *th; - - if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, vl->plugin, NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, vl->plugin, NULL, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, "", NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get (vl->host, "", NULL, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get ("", vl->plugin, NULL, - vl->type, NULL)) != NULL) - return (th); - else if ((th = threshold_get ("", "", NULL, - vl->type, vl->type_instance)) != NULL) - return (th); - else if ((th = threshold_get ("", "", NULL, - vl->type, NULL)) != NULL) - return (th); - - return (NULL); -} /* threshold_t *threshold_search */ - /* * int ut_report_state * @@ -644,7 +678,12 @@ static int ut_report_state (const data_set_t *ds, /* Send an okay notification */ if (state == STATE_OKAY) { - status = ssnprintf (buf, bufsize, ": All data sources are within range again."); + if (state_old == STATE_MISSING) + status = ssnprintf (buf, bufsize, + ": Value is no longer missing."); + else + status = ssnprintf (buf, bufsize, + ": All data sources are within range again."); buf += status; bufsize -= status; } @@ -855,7 +894,8 @@ static int ut_check_one_threshold (const data_set_t *ds, * Returns zero on success and if no threshold has been configured. Returns * less than zero on failure. */ -int ut_check_threshold (const data_set_t *ds, const value_list_t *vl) +static int ut_check_threshold (const data_set_t *ds, const value_list_t *vl, + __attribute__((unused)) user_data_t *ud) { /* {{{ */ threshold_t *th; gauge_t *values; @@ -918,92 +958,11 @@ int ut_check_threshold (const data_set_t *ds, const value_list_t *vl) return (0); } /* }}} int ut_check_threshold */ -/* - * int ut_check_interesting (PUBLIC) - * - * Given an identification returns - * 0: No threshold is defined. - * 1: A threshold has been found. The flag `persist' is off. - * 2: A threshold has been found. The flag `persist' is on. - * (That is, it is expected that many notifications are sent until the - * problem disappears.) - */ -int ut_check_interesting (const char *name) -{ /* {{{ */ - char *name_copy = NULL; - char *host = NULL; - char *plugin = NULL; - char *plugin_instance = NULL; - char *type = NULL; - char *type_instance = NULL; - int status; - data_set_t ds; - value_list_t vl; - threshold_t *th; - - /* If there is no tree nothing is interesting. */ - if (threshold_tree == NULL) - return (0); - - name_copy = strdup (name); - if (name_copy == NULL) - { - ERROR ("ut_check_interesting: strdup failed."); - return (-1); - } - - status = parse_identifier (name_copy, &host, - &plugin, &plugin_instance, &type, &type_instance); - if (status != 0) - { - ERROR ("ut_check_interesting: parse_identifier failed."); - sfree (name_copy); - return (-1); - } - - memset (&ds, '\0', sizeof (ds)); - memset (&vl, '\0', sizeof (vl)); - - sstrncpy (vl.host, host, sizeof (vl.host)); - sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); - if (plugin_instance != NULL) - sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - sstrncpy (ds.type, type, sizeof (ds.type)); - sstrncpy (vl.type, type, sizeof (vl.type)); - if (type_instance != NULL) - sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - - sfree (name_copy); - host = plugin = plugin_instance = type = type_instance = NULL; - - th = threshold_search (&vl); - if (th == NULL) - return (0); - - if ((th->flags & UT_FLAG_INTERESTING) == 0) - return (0); - - if ((th->flags & UT_FLAG_PERSIST) == 0) - return (1); - return (2); -} /* }}} int ut_check_interesting */ - -int ut_search_threshold (const value_list_t *vl, /* {{{ */ - threshold_t *ret_threshold) +void module_register (void) { - threshold_t *t; - - if (vl == NULL) - return (EINVAL); - - t = threshold_search (vl); - if (t == NULL) - return (ENOENT); - - memcpy (ret_threshold, t, sizeof (*ret_threshold)); - ret_threshold->next = NULL; - - return (0); -} /* }}} int ut_search_threshold */ + plugin_register_complex_config ("threshold", ut_config); + plugin_register_write ("threshold", ut_check_threshold, + /* user data = */ NULL); +} /* vim: set sw=2 ts=8 sts=2 tw=78 et fdm=marker : */ diff --git a/src/utils_cache.c b/src/utils_cache.c index 7e1dcf75..2ed58706 100644 --- a/src/utils_cache.c +++ b/src/utils_cache.c @@ -24,7 +24,6 @@ #include "plugin.h" #include "utils_avltree.h" #include "utils_cache.h" -#include "utils_threshold.h" #include "meta_data.h" #include @@ -436,9 +435,6 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) { char name[6 * DATA_MAX_NAME_LEN]; cache_entry_t *ce = NULL; - int send_okay_notification = 0; - cdtime_t update_delay = 0; - notification_t n; int status; int i; @@ -472,15 +468,6 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) return (-1); } - /* Send a notification (after the lock has been released) if we switch the - * state from something else to `okay'. */ - if (ce->state == STATE_MISSING) - { - send_okay_notification = 1; - ce->state = STATE_OKAY; - update_delay = cdtime () - ce->last_update; - } - for (i = 0; i < ds->ds_num; i++) { switch (ds->ds[i].type) @@ -567,28 +554,6 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) pthread_mutex_unlock (&cache_lock); - if (send_okay_notification == 0) - return (0); - - /* Do not send okay notifications for uninteresting values, i. e. values for - * which no threshold is configured. */ - status = ut_check_interesting (name); - if (status <= 0) - return (0); - - /* Initialize the notification */ - memset (&n, '\0', sizeof (n)); - NOTIFICATION_INIT_VL (&n, vl, ds); - - n.severity = NOTIF_OKAY; - n.time = vl->time; - - ssnprintf (n.message, sizeof (n.message), - "Received a value for %s. It was missing for %u seconds.", - name, (unsigned int) update_delay); - - plugin_dispatch_notification (&n); - return (0); } /* int uc_update */ diff --git a/src/utils_threshold.h b/src/utils_threshold.h deleted file mode 100644 index 5955ca6e..00000000 --- a/src/utils_threshold.h +++ /dev/null @@ -1,87 +0,0 @@ -/** - * collectd - src/utils_threshold.h - * Copyright (C) 2007-2009 Florian octo 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 - * - * Author: - * Florian octo Forster - **/ - -#ifndef UTILS_THRESHOLD_H -#define UTILS_THRESHOLD_H 1 - -#include "collectd.h" -#include "liboconfig/oconfig.h" -#include "plugin.h" - -typedef struct threshold_s -{ - char host[DATA_MAX_NAME_LEN]; - char plugin[DATA_MAX_NAME_LEN]; - char plugin_instance[DATA_MAX_NAME_LEN]; - char type[DATA_MAX_NAME_LEN]; - char type_instance[DATA_MAX_NAME_LEN]; - char data_source[DATA_MAX_NAME_LEN]; - gauge_t warning_min; - gauge_t warning_max; - gauge_t failure_min; - gauge_t failure_max; - gauge_t hysteresis; - unsigned int flags; - int hits; - struct threshold_s *next; -} threshold_t; - -/* - * ut_config - * - * Parses the configuration and sets up the module. This is called from - * `src/configfile.c'. - */ -int ut_config (const oconfig_item_t *ci); - -/* - * ut_check_threshold - * - * Checks if a threshold is defined for this value and if such a threshold is - * configured, check if the value within the acceptable range. If it is not, a - * notification is dispatched to inform the user that a problem exists. This is - * called from `plugin_read_all'. - */ -int ut_check_threshold (const data_set_t *ds, const value_list_t *vl); - -/* - * Given an identification returns - * 0: No threshold is defined. - * 1: A threshold has been found. The flag `persist' is off. - * 2: A threshold has been found. The flag `persist' is on. - * (That is, it is expected that many notifications are sent until the - * problem disappears.) - */ -int ut_check_interesting (const char *name); - -/* - * Given an identifier in form of a `value_list_t', searches for the best - * matching threshold configuration. `ret_threshold' may be NULL. - * - * Returns: - * 0: Success. Threshold configuration has been copied to - * `ret_threshold' (if it is non-NULL). - * ENOENT: No configuration for this identifier found. - * else: Error. - */ -int ut_search_threshold (const value_list_t *vl, threshold_t *ret_threshold); - -#endif /* UTILS_THRESHOLD_H */ -- 2.11.0