summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e62c372)
raw | patch | inline | side by side (parent: e62c372)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 1 Nov 2007 10:50:14 +0000 (11:50 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 1 Nov 2007 10:50:14 +0000 (11:50 +0100) |
This function is called from `plugin_dispatch_values' and prints a warning when
the values is outside of the configured threshold.
the values is outside of the configured threshold.
src/plugin.c | patch | blob | history | |
src/utils_threshold.c | patch | blob | history | |
src/utils_threshold.h | patch | blob | history |
diff --git a/src/plugin.c b/src/plugin.c
index 67d61880ee963c5cc4fc2403d9da8c3c274f0a3b..84b7e0be9f175e0f1ed6b0e4321e7e20c7a42e3f 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
#include "configfile.h"
#include "utils_llist.h"
#include "utils_cache.h"
+#include "utils_threshold.h"
/*
* Private structures
/* Update the value cache */
uc_update (ds, vl);
+ ut_check_threshold (ds, vl);
le = llist_head (list_write);
while (le != NULL)
diff --git a/src/utils_threshold.c b/src/utils_threshold.c
index 03bc4233b330776fa3cc2ae232518b97579c10a2..91407e0cbffa531468b86e1e81fc8aa9fb3b987d 100644 (file)
--- a/src/utils_threshold.c
+++ b/src/utils_threshold.c
/*
* Private data structures
- */
+ * {{{ */
typedef struct threshold_s
{
char host[DATA_MAX_NAME_LEN];
gauge_t max;
int invert;
} threshold_t;
+/* }}} */
/*
* Private (static) variables
- */
+ * {{{ */
static avl_tree_t *threshold_tree = NULL;
static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER;
+/* }}} */
/*
* Threshold management
* ====================
* The following functions add, delete, search, etc. configured thresholds to
* the underlying AVL trees.
- */
+ * {{{ */
static int ut_threshold_add (const threshold_t *th)
{
char name[6 * DATA_MAX_NAME_LEN];
} /* int ut_threshold_add */
/*
* End of the threshold management functions
- */
+ * }}} */
/*
* Configuration
* =============
- * The following approximately two hundred functions are used to convert the
- * threshold values..
- */
+ * The following approximately two hundred functions are used to handle the
+ * configuration and fill the threshold list.
+ * {{{ */
static int ut_config_type_instance (threshold_t *th, oconfig_item_t *ci)
{
if ((ci->values_num != 1)
/*
* End of the functions used to configure threshold values.
*/
+/* }}} */
+
+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;
+
+ format_name (name, sizeof (name),
+ (hostname == NULL) ? "" : hostname,
+ (plugin == NULL) ? "" : plugin, plugin_instance,
+ (type == NULL) ? "" : type, type_instance);
+ name[sizeof (name) - 1] = '\0';
+
+ if (avl_get (threshold_tree, name, (void *) &th) == 0)
+ return (th);
+ else
+ return (NULL);
+} /* threshold_t *threshold_get */
+
+static threshold_t *threshold_search (const data_set_t *ds,
+ const value_list_t *vl)
+{
+ threshold_t *th;
+
+ if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
+ ds->type, vl->type_instance)) != NULL)
+ return (th);
+ else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
+ ds->type, NULL)) != NULL)
+ return (th);
+ else if ((th = threshold_get (vl->host, vl->plugin, NULL,
+ ds->type, vl->type_instance)) != NULL)
+ return (th);
+ else if ((th = threshold_get (vl->host, vl->plugin, NULL,
+ ds->type, NULL)) != NULL)
+ return (th);
+ else if ((th = threshold_get (vl->host, "", NULL,
+ ds->type, vl->type_instance)) != NULL)
+ return (th);
+ else if ((th = threshold_get (vl->host, "", NULL,
+ ds->type, NULL)) != NULL)
+ return (th);
+ else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
+ ds->type, vl->type_instance)) != NULL)
+ return (th);
+ else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
+ ds->type, NULL)) != NULL)
+ return (th);
+ else if ((th = threshold_get ("", vl->plugin, NULL,
+ ds->type, vl->type_instance)) != NULL)
+ return (th);
+ else if ((th = threshold_get ("", vl->plugin, NULL,
+ ds->type, NULL)) != NULL)
+ return (th);
+ else if ((th = threshold_get ("", "", NULL,
+ ds->type, vl->type_instance)) != NULL)
+ return (th);
+ else if ((th = threshold_get ("", "", NULL,
+ ds->type, NULL)) != NULL)
+ return (th);
+
+ return (NULL);
+} /* threshold_t *threshold_search */
+
+int ut_check_threshold (const data_set_t *ds, const value_list_t *vl)
+{
+ threshold_t *th;
+ gauge_t *values;
+ int i;
+
+ if (threshold_tree == NULL)
+ return (0);
+ pthread_mutex_lock (&threshold_lock);
+ th = threshold_search (ds, vl);
+ pthread_mutex_unlock (&threshold_lock);
+ if (th == NULL)
+ return (0);
+
+ DEBUG ("Found matching threshold");
+
+ values = uc_get_rate (ds, vl);
+ if (values == NULL)
+ return (0);
+
+ for (i = 0; i < ds->ds_num; i++)
+ {
+ if ((th->min > values[i]) || (th->max < values[i]))
+ WARNING ("ut_check_threshold: ds%i: %lf <= !%lf <= %lf",
+ i, th->min, values[i], th->max);
+ }
+
+ sfree (values);
+
+ return (0);
+} /* int ut_check_threshold */
-/* vim: set sw=2 ts=8 sts=2 tw=78 : */
+/* vim: set sw=2 ts=8 sts=2 tw=78 fdm=marker : */
diff --git a/src/utils_threshold.h b/src/utils_threshold.h
index 6f7d47e20316d8d457125fddf9a6abb259e9d767..9c347b977b552213da8818f35537658a121b5f24 100644 (file)
--- a/src/utils_threshold.h
+++ b/src/utils_threshold.h
#include "collectd.h"
#include "liboconfig/oconfig.h"
+#include "plugin.h"
int ut_config (const oconfig_item_t *ci);
+int ut_check_threshold (const data_set_t *ds, const value_list_t *vl);
#endif /* UTILS_THRESHOLD_H */