[collectd] Patch: Support custom CPU interval v2
Lee Hardy
lee at leeh.co.uk
Sun Mar 9 18:47:48 CET 2014
Hey,
I've updated the CPU interval patch to make it more generic, by adding a
plugin_update_interval() function called as part of the config function so
I can update other plugins more easily.
When the aggregation module is enabled for CPU information though, it seems
to be throwing an error:
Mar 9 17:22:36 rpm-i386 collectd[26640]: plugin_value_list_clone: Unable to
determine interval from context for value list
"rpm-i386.build.local/aggregation-cpu-average/cpu-idle". This indicates a
broken plugin. Please report this problem to the collectd mailing list or
at <http://collectd.org/bugs/>.
This seems to happen even when I specify the interval via
plugin_register_complex_read() as well, so I'm not entirely sure if I've
missed something or there is some issue with the aggregation module.
Anyone have any ideas?
Cheers,
Lee H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20140309/f982f47c/attachment.html>
-------------- next part --------------
diff -ur collectd-5.4.1-old/src/cpu.c collectd-5.4.1/src/cpu.c
--- collectd-5.4.1-old/src/cpu.c 2014-01-26 08:09:23.528559863 +0000
+++ collectd-5.4.1/src/cpu.c 2014-03-09 16:29:08.795004019 +0000
@@ -28,6 +28,7 @@
#include "collectd.h"
#include "common.h"
#include "plugin.h"
+#include "utils_time.h"
#ifdef HAVE_MACH_KERN_RETURN_H
# include <mach/kern_return.h>
@@ -145,6 +146,12 @@
static int pnumcpu;
#endif /* HAVE_PERFSTAT */
+static const char *config_keys[] =
+{
+ "Interval"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
static int init (void)
{
#if PROCESSOR_CPU_LOAD_INFO || PROCESSOR_TEMPERATURE
@@ -241,6 +248,38 @@
return (0);
} /* int init */
+static int cpu_config (const char *key, const char *value) /* {{{ */
+{
+ if (strcasecmp (key, "Interval") == 0)
+ {
+ double tmp;
+
+ tmp = atof (value);
+ if (tmp > 0.0)
+ {
+ cdtime_t cpu_interval = DOUBLE_TO_CDTIME_T (tmp);
+
+ if(cpu_interval)
+ {
+ plugin_update_interval("cpu", cpu_interval);
+ return (0);
+ }
+ }
+
+ WARNING ("cpu plugin: Ignoring invalid interval %g (%s)",
+ tmp, value);
+ return (-1);
+ }
+ else
+ {
+ return (-1);
+ }
+
+ return (0);
+} /* }}} int cpu_config */
+
+
+
static void submit (int cpu_num, const char *type_instance, derive_t value)
{
value_t values[1];
@@ -601,6 +640,9 @@
void module_register (void)
{
+ plugin_register_config ("cpu", cpu_config,
+ config_keys, config_keys_num);
+
plugin_register_init ("cpu", init);
plugin_register_read ("cpu", cpu_read);
} /* void module_register */
diff -ur collectd-5.4.1-old/src/plugin.c collectd-5.4.1/src/plugin.c
--- collectd-5.4.1-old/src/plugin.c 2014-01-26 08:09:23.536560018 +0000
+++ collectd-5.4.1/src/plugin.c 2014-03-09 17:21:35.544004020 +0000
@@ -1217,6 +1217,48 @@
(void *) callback, /* user_data = */ NULL));
} /* int plugin_register_shutdown */
+int plugin_update_interval (const char *name, cdtime_t interval)
+{
+ read_func_t *rf;
+ llentry_t *le;
+/* plugin_ctx_t old_ctx;*/
+
+ pthread_mutex_lock (&read_lock);
+
+ if (read_list == NULL)
+ {
+ pthread_mutex_unlock (&read_lock);
+ ERROR ("plugin_update_interval: read_list empty.");
+ return -1;
+ }
+
+ le = llist_search (read_list, name);
+ if (le == NULL)
+ {
+ pthread_mutex_unlock (&read_lock);
+ WARNING ("The read function \"cpu\" is not registered. "
+ "Check for missing \"LoadPlugin\" lines "
+ "in your configuration.");
+ return (EINVAL);
+ }
+
+ rf = (read_func_t *) le->value;
+
+ rf->rf_interval = interval;
+ rf->rf_effective_interval = interval;
+
+ /* update the interval in the plugin context (?) */
+/*
+ old_ctx = plugin_set_ctx (rf->rf_ctx);
+ plugin_ctx_t ctx = plugin_get_ctx ();
+ ctx.interval = interval;
+ plugin_set_ctx(old_ctx);*/
+
+ pthread_mutex_unlock (&read_lock);
+
+ return 0;
+}
+
static void plugin_free_data_sets (void)
{
void *key;
diff -ur collectd-5.4.1-old/src/plugin.h collectd-5.4.1/src/plugin.h
--- collectd-5.4.1-old/src/plugin.h 2014-01-26 08:09:23.536560018 +0000
+++ collectd-5.4.1/src/plugin.h 2014-03-09 16:34:43.702004071 +0000
@@ -299,6 +299,8 @@
int plugin_register_notification (const char *name,
plugin_notification_cb callback, user_data_t *user_data);
+int plugin_update_interval (const char *name, cdtime_t interval);
+
int plugin_unregister_config (const char *name);
int plugin_unregister_complex_config (const char *name);
int plugin_unregister_init (const char *name);
Only in collectd-5.4.1/src: utils_heap.c.orig
More information about the collectd
mailing list