From: Pierre-Yves Ritschard Date: Tue, 22 Jul 2014 11:45:23 +0000 (+0200) Subject: Store the avl tree within collectd core. X-Git-Tag: collectd-5.5.0~291^2~4 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=59278c8774567122dbc0ea1a217d007782fa868e;p=collectd.git Store the avl tree within collectd core. We need this if we want modules to share access to the threshold avl tree. --- diff --git a/src/Makefile.am b/src/Makefile.am index 30c779b9..8060029a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,7 +39,9 @@ collectd_SOURCES = collectd.c collectd.h \ utils_subst.c utils_subst.h \ utils_tail.c utils_tail.h \ utils_time.c utils_time.h \ - types_list.c types_list.h + types_list.c types_list.h \ + utils_threshold.c utils_threshold.h + collectd_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL) collectd_CFLAGS = $(AM_CFLAGS) diff --git a/src/threshold.c b/src/threshold.c index 7df4d616..922689d3 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -28,44 +28,11 @@ #include "plugin.h" #include "utils_avltree.h" #include "utils_cache.h" +#include "utils_threshold.h" #include #include -/* - * Private data structures - * {{{ */ -#define UT_FLAG_INVERT 0x01 -#define UT_FLAG_PERSIST 0x02 -#define UT_FLAG_PERCENTAGE 0x04 -#define UT_FLAG_INTERESTING 0x08 -#define UT_FLAG_PERSIST_OK 0x10 -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; -/* }}} */ - -/* - * Private (static) variables - * {{{ */ -static c_avl_tree_t *threshold_tree = NULL; -static pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER; -/* }}} */ - /* * Threshold management * ==================== @@ -171,7 +138,7 @@ static int ut_threshold_add (const threshold_t *th) return (status); } /* }}} int ut_threshold_add */ -/* +/* * threshold_t *threshold_search * * Searches for a threshold configuration using all the possible variations of @@ -862,7 +829,7 @@ static int ut_check_one_threshold (const data_set_t *ds, * * Gets a list of matching thresholds and searches for the worst status by one * of the thresholds. Then reports that status using the ut_report_state - * function above. + * function above. * Returns zero on success and if no threshold has been configured. Returns * less than zero on failure. */ @@ -990,7 +957,7 @@ int ut_config (oconfig_item_t *ci) th.hits = 0; th.hysteresis = 0; th.flags = UT_FLAG_INTERESTING; /* interesting by default */ - + for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; diff --git a/src/utils_threshold.c b/src/utils_threshold.c new file mode 100644 index 00000000..005c49c3 --- /dev/null +++ b/src/utils_threshold.c @@ -0,0 +1,34 @@ +/** + * collectd - src/utils_threshold.c + * Copyright (C) 2014 Pierre-Yves Ritschard + * + * 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: + * Pierre-Yves Ritschard + **/ + +#include "collectd.h" +#include "common.h" +#include "utils_avltree.h" +#include "utils_threshold.h" + +#include + +/* + * Exported symbols + * {{{ */ +c_avl_tree_t *threshold_tree = NULL; +pthread_mutex_t threshold_lock = PTHREAD_MUTEX_INITIALIZER; +/* }}} */ diff --git a/src/utils_threshold.h b/src/utils_threshold.h new file mode 100644 index 00000000..d1abf563 --- /dev/null +++ b/src/utils_threshold.h @@ -0,0 +1,53 @@ +/** + * collectd - src/utils_threshold.h + * Copyright (C) 2014 Pierre-Yves Ritschard + * + * 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: + * Pierre-Yves Ritschard + **/ + +#ifndef UTILS_THRESHOLD_H +#define UTILS_THRESHOLD_H 1 + +#define UT_FLAG_INVERT 0x01 +#define UT_FLAG_PERSIST 0x02 +#define UT_FLAG_PERCENTAGE 0x04 +#define UT_FLAG_INTERESTING 0x08 +#define UT_FLAG_PERSIST_OK 0x10 +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; + +extern c_avl_tree_t *threshold_tree; +extern pthread_mutex_t threshold_lock; + +#endif /* UTILS_THRESHOLD_H */ + +/* vim: set sw=2 sts=2 ts=8 : */