Commit b7d9f8ad authored by Robert Dietrich's avatar Robert Dietrich

added patch to provide AlignRead and AlignReadOffset options

parent bbd12c54
diff -ruN daemon.save/configfile.c daemon/configfile.c
--- daemon.save/configfile.c 2020-03-08 16:57:09.000000000 +0100
+++ daemon/configfile.c 2020-04-15 08:49:22.000000000 +0200
@@ -106,6 +106,7 @@
{"Hostname", NULL, 0, NULL},
{"FQDNLookup", NULL, 0, "true"},
{"Interval", NULL, 0, NULL},
+ {"AlignRead", NULL, 0, "false"},
{"ReadThreads", NULL, 0, "5"},
{"WriteThreads", NULL, 0, "5"},
{"WriteQueueLimitHigh", NULL, 0, NULL},
@@ -302,7 +303,12 @@
cf_util_get_cdtime(child, &ctx.flush_interval);
else if (strcasecmp("FlushTimeout", child->key) == 0)
cf_util_get_cdtime(child, &ctx.flush_timeout);
- else {
+ else if (strcasecmp("AlignRead", child->key) == 0)
+ cf_util_get_boolean(child, &ctx.align_read);
+ else if (strcasecmp("AlignReadOffset", child->key) == 0) {
+ cf_util_get_cdtime(child, &ctx.align_read_offset);
+ ctx.align_read = true;
+ } else {
WARNING("Ignoring unknown LoadPlugin option \"%s\" "
"for plugin \"%s\"",
child->key, name);
@@ -813,7 +819,7 @@
return root;
} /* oconfig_item_t *cf_read_generic */
- /* #endif HAVE_WORDEXP_H */
+/* #endif HAVE_WORDEXP_H */
#else /* if !HAVE_WORDEXP_H */
static oconfig_item_t *cf_read_generic(const char *path, const char *pattern,
diff -ruN daemon.save/plugin.c daemon/plugin.c
--- daemon.save/plugin.c 2020-03-08 16:57:09.000000000 +0100
+++ daemon/plugin.c 2020-04-14 20:33:19.000000000 +0200
@@ -447,6 +447,46 @@
return 0;
}
+/*
+ * Set the time of the next read for the given read function. If AlignRead is
+ * enabled, the next read time is set to a multiple of interval.
+ * AlignReadOffset delays the call of aligned read functions accordingly.
+ */
+static void plugin_set_next_read(read_func_t *rf, bool verbose) {
+ /* If read alignment is disabled, start reading immediately. */
+ if (!rf->rf_ctx.align_read) {
+ rf->rf_next_read = cdtime();
+ return;
+ }
+
+ cdtime_t read_offset = rf->rf_ctx.align_read_offset;
+ cdtime_t interval = rf->rf_interval;
+
+ /* read offset greater than or equal to interval does not make sense */
+ if (read_offset >= interval) {
+ if (verbose) {
+ WARNING("Plugin '%s': Ignoring read offset %.3lf for '%s'. It has to be "
+ "smaller than interval (%.3lf)!",
+ rf->rf_ctx.name, CDTIME_T_TO_DOUBLE(read_offset), rf->rf_name,
+ CDTIME_T_TO_DOUBLE(interval));
+ }
+ read_offset = 0;
+ }
+
+ cdtime_t now = cdtime();
+ rf->rf_next_read = now - (now % interval) + read_offset;
+ if (rf->rf_next_read < now) {
+ rf->rf_next_read += interval;
+ }
+
+ if (verbose) {
+ char date[26];
+ rfc3339_local(date, sizeof(date), rf->rf_next_read);
+ INFO("Plugin '%s': Read function '%s' starts at %s", rf->rf_ctx.name,
+ rf->rf_name, date);
+ }
+} /* void plugin_set_next_read */
+
static void *plugin_read_thread(void __attribute__((unused)) * args) {
while (read_loop != 0) {
read_func_t *rf;
@@ -585,10 +625,9 @@
/* Check, if `rf_next_read' is in the past. */
if (rf->rf_next_read < now) {
- /* `rf_next_read' is in the past. Insert `now'
- * so this value doesn't trail off into the
- * past too much. */
- rf->rf_next_read = now;
+ /* `rf_next_read' is in the past. Insert `now' or an aligned value in the
+ * future so this value doesn't trail off into the past too much. */
+ plugin_set_next_read(rf, false);
}
DEBUG("plugin_read_thread: Next read of the `%s' plugin at %.3f.",
@@ -1092,7 +1131,7 @@
int status;
llentry_t *le;
- rf->rf_next_read = cdtime();
+ plugin_set_next_read(rf, true);
rf->rf_effective_interval = rf->rf_interval;
pthread_mutex_lock(&read_lock);
diff -ruN daemon.save/plugin.h daemon/plugin.h
--- daemon.save/plugin.h 2020-03-08 16:57:09.000000000 +0100
+++ daemon/plugin.h 2020-04-14 17:05:37.000000000 +0200
@@ -185,6 +185,8 @@
cdtime_t interval;
cdtime_t flush_interval;
cdtime_t flush_timeout;
+ bool align_read;
+ cdtime_t align_read_offset;
};
typedef struct plugin_ctx_s plugin_ctx_t;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment