collectd: adjust reaction to ntp time at boot time
authorHannu Nyman <redacted>
Sun, 3 Nov 2019 15:48:11 +0000 (17:48 +0200)
committerHannu Nyman <redacted>
Sun, 3 Nov 2019 15:54:22 +0000 (17:54 +0200)
Adjust the reaction to a polling interval timestamp that references
to a past time.

Past timestamps can happen when ntpd adjusts router's time after network
connectivity is obtained after boot. Collectd shows warnings for each plugin
as it tries to enter new values with the same timestamp as the previous one.

This patch adjusts the next polling time to be now+2 seconds for the main
loop and for the plugin-specific read loops. That avoids the warnings, but
does not overreact in case there are shorter polling intervals or the time
gets adjusted for other reasons.

Additionally some debug statements are aded, but they are visible only
when --enable-debug configure option is used in Makefile.

Signed-off-by: Hannu Nyman <redacted>
utils/collectd/Makefile
utils/collectd/patches/320-reaction-to-ntp-time-change-at-boot.patch [new file with mode: 0644]

index fc3695c78bc3b6dfc2b20e9bbd8acacdeebc0985..94e591996ca7493437b7e86a5998318fb06f0391 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=collectd
 PKG_VERSION:=5.9.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=https://collectd.org/files/ \
diff --git a/utils/collectd/patches/320-reaction-to-ntp-time-change-at-boot.patch b/utils/collectd/patches/320-reaction-to-ntp-time-change-at-boot.patch
new file mode 100644 (file)
index 0000000..6440a13
--- /dev/null
@@ -0,0 +1,61 @@
+Adjust the reaction to a polling interval timestamp that references
+to a past time.
+
+Past timestamps can happen when ntpd adjusts router's time after network
+connectivity is obtained after boot. Collectd shows warnings for each plugin
+as it tries to enter new values with the same timestamp as the previous one.
+
+This patch adjusts the next polling time to be now+2 seconds for the main
+loop and for the plugin-specific read loops. That avoids the warnings, but
+does not overreact in case there are shorter polling intervals or the time
+gets adjusted for other reasons.
+
+Additionally some debug statements are added, but they are visible only
+when --enable-debug configure option is used in Makefile.
+
+
+--- a/src/daemon/collectd.c
++++ b/src/daemon/collectd.c
+@@ -274,20 +274,23 @@ static int do_loop(void) {
+     update_kstat();
+ #endif
++    DEBUG("do_loop before plugin_read_all: now = %.3f", CDTIME_T_TO_DOUBLE(cdtime()));
+     /* Issue all plugins */
+     plugin_read_all();
+     cdtime_t now = cdtime();
++    DEBUG("do_loop after plugin_read_all: now = %.3f, wait_until= %.3f", CDTIME_T_TO_DOUBLE(now), CDTIME_T_TO_DOUBLE(wait_until));
+     if (now >= wait_until) {
+-      WARNING("Not sleeping because the next interval is "
++      WARNING("Sleeping only 2s because the next interval is "
+               "%.3f seconds in the past!",
+               CDTIME_T_TO_DOUBLE(now - wait_until));
+-      wait_until = now + interval;
+-      continue;
++      wait_until = now + DOUBLE_TO_CDTIME_T(2);
++      DEBUG("do_loop: wait_until adjusted to now+2 = %.3f", CDTIME_T_TO_DOUBLE(wait_until));
+     }
+     struct timespec ts_wait = CDTIME_T_TO_TIMESPEC(wait_until - now);
+     wait_until = wait_until + interval;
++    DEBUG("do_loop ends: wait_until set to %.3f", CDTIME_T_TO_DOUBLE(wait_until));
+     while ((loop == 0) && (nanosleep(&ts_wait, &ts_wait) != 0)) {
+       if (errno != EINTR) {
+--- a/src/daemon/plugin.c
++++ a/src/daemon/plugin.c
+@@ -578,10 +578,11 @@
+     /* Check, if `rf_next_read' is in the past. */
+     if (rf->rf_next_read < now) {
+-      /* `rf_next_read' is in the past. Insert `now'
++      /* `rf_next_read' is in the past. Insert `now'+2s
+        * so this value doesn't trail off into the
+        * past too much. */
+-      rf->rf_next_read = now;
++      rf->rf_next_read = now + DOUBLE_TO_CDTIME_T(2);
++      DEBUG("plugin_read_thread: Next read is in the past. Adjusted to now+2s");
+     }
+     DEBUG("plugin_read_thread: Next read of the `%s' plugin at %.3f.",
git clone https://git.99rst.org/PROJECT