src/daemon/collectd.h \
src/daemon/configfile.c \
src/daemon/configfile.h \
+ src/daemon/data_set.c \
+ src/daemon/data_set.h \
src/daemon/filter_chain.c \
src/daemon/filter_chain.h \
src/daemon/globals.c \
--- /dev/null
+/**
+ * collectd - src/daemon/data_set.c
+ * Copyright (C) 2005-2023 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ * Sebastian Harl <sh at tokkee.org>
+ * Manoj Srivastava <srivasta at google.com>
+ **/
+
+#include "daemon/data_set.h"
+#include "daemon/plugin.h"
+#include "utils/avltree/avltree.h"
+#include "utils/common/common.h"
+
+#ifdef WIN32
+#define EXPORT __declspec(dllexport)
+#include <sys/stat.h>
+#include <unistd.h>
+#else
+#define EXPORT
+#endif
+
+static c_avl_tree_t *data_sets;
+
+EXPORT int plugin_register_data_set(const data_set_t *ds) {
+ data_set_t *ds_copy;
+
+ if ((data_sets != NULL) && (c_avl_get(data_sets, ds->type, NULL) == 0)) {
+ NOTICE("Replacing DS `%s' with another version.", ds->type);
+ plugin_unregister_data_set(ds->type);
+ } else if (data_sets == NULL) {
+ data_sets = c_avl_create((int (*)(const void *, const void *))strcmp);
+ if (data_sets == NULL)
+ return -1;
+ }
+
+ ds_copy = malloc(sizeof(*ds_copy));
+ if (ds_copy == NULL)
+ return -1;
+ memcpy(ds_copy, ds, sizeof(data_set_t));
+
+ ds_copy->ds = malloc(sizeof(*ds_copy->ds) * ds->ds_num);
+ if (ds_copy->ds == NULL) {
+ sfree(ds_copy);
+ return -1;
+ }
+
+ for (size_t i = 0; i < ds->ds_num; i++)
+ memcpy(ds_copy->ds + i, ds->ds + i, sizeof(data_source_t));
+
+ return c_avl_insert(data_sets, (void *)ds_copy->type, (void *)ds_copy);
+} /* int plugin_register_data_set */
+
+EXPORT int plugin_unregister_data_set(const char *name) {
+ data_set_t *ds;
+
+ if (data_sets == NULL)
+ return -1;
+
+ if (c_avl_remove(data_sets, name, NULL, (void *)&ds) != 0)
+ return -1;
+
+ sfree(ds->ds);
+ sfree(ds);
+
+ return 0;
+} /* int plugin_unregister_data_set */
+
+EXPORT const data_set_t *plugin_get_ds(const char *name) {
+ data_set_t *ds;
+
+ if (data_sets == NULL) {
+ P_ERROR("plugin_get_ds: No data sets are defined yet.");
+ return NULL;
+ }
+
+ if (c_avl_get(data_sets, name, (void *)&ds) != 0) {
+ DEBUG("No such dataset registered: %s", name);
+ return NULL;
+ }
+
+ return ds;
+} /* data_set_t *plugin_get_ds */
+
+void plugin_free_data_sets(void) {
+ void *key;
+ void *value;
+
+ if (data_sets == NULL)
+ return;
+
+ while (c_avl_pick(data_sets, &key, &value) == 0) {
+ data_set_t *ds = value;
+ /* key is a pointer to ds->type */
+
+ sfree(ds->ds);
+ sfree(ds);
+ }
+
+ c_avl_destroy(data_sets);
+ data_sets = NULL;
+} /* void plugin_free_data_sets */
--- /dev/null
+/**
+ * collectd - src/daemon/data_set.h
+ * Copyright (C) 2005-2023 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ * Sebastian Harl <sh at tokkee.org>
+ * Manoj Srivastava <srivasta at google.com>
+ **/
+
+#ifndef DAEMON_DATA_SET_H
+#define DAEMON_DATA_SET_H
+
+#include "collectd.h"
+
+struct data_source_s {
+ char name[DATA_MAX_NAME_LEN];
+ int type;
+ double min;
+ double max;
+};
+typedef struct data_source_s data_source_t;
+
+struct data_set_s {
+ char type[DATA_MAX_NAME_LEN];
+ size_t ds_num;
+ data_source_t *ds;
+};
+typedef struct data_set_s data_set_t;
+
+int plugin_register_data_set(const data_set_t *ds);
+int plugin_unregister_data_set(const char *name);
+const data_set_t *plugin_get_ds(const char *name);
+void plugin_free_data_sets(void);
+
+#endif /* DAEMON_DATA_SET_H */
/**
- * collectd - src/plugin.c
+ * collectd - src/daemon/plugin.c
* Copyright (C) 2005-2014 Florian octo Forster
*
* Permission is hereby granted, free of charge, to any person obtaining a
#include "collectd.h"
#include "configfile.h"
+#include "daemon/data_set.h"
#include "filter_chain.h"
#include "plugin.h"
#include "resource.h"
static fc_chain_t *pre_cache_chain;
static fc_chain_t *post_cache_chain;
-static c_avl_tree_t *data_sets;
-
static char *plugindir;
#ifndef DEFAULT_MAX_READ_INTERVAL
return create_register_callback(&list_shutdown, name, (void *)callback, NULL);
} /* int plugin_register_shutdown */
-static void plugin_free_data_sets(void) {
- void *key;
- void *value;
-
- if (data_sets == NULL)
- return;
-
- while (c_avl_pick(data_sets, &key, &value) == 0) {
- data_set_t *ds = value;
- /* key is a pointer to ds->type */
-
- sfree(ds->ds);
- sfree(ds);
- }
-
- c_avl_destroy(data_sets);
- data_sets = NULL;
-} /* void plugin_free_data_sets */
-
-EXPORT int plugin_register_data_set(const data_set_t *ds) {
- data_set_t *ds_copy;
-
- if ((data_sets != NULL) && (c_avl_get(data_sets, ds->type, NULL) == 0)) {
- NOTICE("Replacing DS `%s' with another version.", ds->type);
- plugin_unregister_data_set(ds->type);
- } else if (data_sets == NULL) {
- data_sets = c_avl_create((int (*)(const void *, const void *))strcmp);
- if (data_sets == NULL)
- return -1;
- }
-
- ds_copy = malloc(sizeof(*ds_copy));
- if (ds_copy == NULL)
- return -1;
- memcpy(ds_copy, ds, sizeof(data_set_t));
-
- ds_copy->ds = malloc(sizeof(*ds_copy->ds) * ds->ds_num);
- if (ds_copy->ds == NULL) {
- sfree(ds_copy);
- return -1;
- }
-
- for (size_t i = 0; i < ds->ds_num; i++)
- memcpy(ds_copy->ds + i, ds->ds + i, sizeof(data_source_t));
-
- return c_avl_insert(data_sets, (void *)ds_copy->type, (void *)ds_copy);
-} /* int plugin_register_data_set */
-
EXPORT int plugin_register_log(const char *name, plugin_log_cb callback,
user_data_t const *ud) {
return create_register_callback(&list_log, name, (void *)callback, ud);
return plugin_unregister(list_shutdown, name);
}
-EXPORT int plugin_unregister_data_set(const char *name) {
- data_set_t *ds;
-
- if (data_sets == NULL)
- return -1;
-
- if (c_avl_remove(data_sets, name, NULL, (void *)&ds) != 0)
- return -1;
-
- sfree(ds->ds);
- sfree(ds);
-
- return 0;
-} /* int plugin_unregister_data_set */
-
EXPORT int plugin_unregister_log(const char *name) {
return plugin_unregister(list_log, name);
}
return notif_severity;
} /* int parse_notif_severity */
-EXPORT const data_set_t *plugin_get_ds(const char *name) {
- data_set_t *ds;
-
- if (data_sets == NULL) {
- P_ERROR("plugin_get_ds: No data sets are defined yet.");
- return NULL;
- }
-
- if (c_avl_get(data_sets, name, (void *)&ds) != 0) {
- DEBUG("No such dataset registered: %s", name);
- return NULL;
- }
-
- return ds;
-} /* data_set_t *plugin_get_ds */
-
static int plugin_notification_meta_add(notification_t *n, const char *name,
enum notification_meta_type_e type,
const void *value) {
};
typedef struct identifier_s identifier_t;
-struct data_source_s {
- char name[DATA_MAX_NAME_LEN];
- int type;
- double min;
- double max;
-};
-typedef struct data_source_s data_source_t;
-
-struct data_set_s {
- char type[DATA_MAX_NAME_LEN];
- size_t ds_num;
- data_source_t *ds;
-};
-typedef struct data_set_s data_set_t;
-
enum notification_meta_type_e {
NM_TYPE_STRING,
NM_TYPE_SIGNED_INT,
plugin_cache_event_cb callback,
user_data_t const *ud);
int plugin_register_shutdown(const char *name, plugin_shutdown_cb callback);
-int plugin_register_data_set(const data_set_t *ds);
int plugin_register_log(const char *name, plugin_log_cb callback,
user_data_t const *user_data);
int plugin_register_notification(const char *name,
int plugin_unregister_missing(const char *name);
int plugin_unregister_cache_event(const char *name);
int plugin_unregister_shutdown(const char *name);
-int plugin_unregister_data_set(const char *name);
int plugin_unregister_log(const char *name);
int plugin_unregister_notification(const char *name);
#define P_NOTICE(...) daemon_log(LOG_NOTICE, __VA_ARGS__)
#define P_INFO(...) daemon_log(LOG_INFO, __VA_ARGS__)
-const data_set_t *plugin_get_ds(const char *name);
-
int plugin_notification_meta_add_string(notification_t *n, const char *name,
const char *value);
int plugin_notification_meta_add_signed_int(notification_t *n, const char *name,