You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.5 KiB

  1. Adjust the reaction to a polling interval timestamp that references
  2. to a past time.
  3. Past timestamps can happen when ntpd adjusts router's time after network
  4. connectivity is obtained after boot. Collectd shows warnings for each plugin
  5. as it tries to enter new values with the same timestamp as the previous one.
  6. This patch adjusts the next polling time to be now+2 seconds for the main
  7. loop and for the plugin-specific read loops. That avoids the warnings, but
  8. does not overreact in case there are shorter polling intervals or the time
  9. gets adjusted for other reasons.
  10. Additionally some debug statements are added, but they are visible only
  11. when --enable-debug configure option is used in Makefile.
  12. --- a/src/daemon/collectd.c
  13. +++ b/src/daemon/collectd.c
  14. @@ -274,20 +274,23 @@ static int do_loop(void) {
  15. update_kstat();
  16. #endif
  17. + DEBUG("do_loop before plugin_read_all: now = %.3f", CDTIME_T_TO_DOUBLE(cdtime()));
  18. /* Issue all plugins */
  19. plugin_read_all();
  20. cdtime_t now = cdtime();
  21. + DEBUG("do_loop after plugin_read_all: now = %.3f, wait_until= %.3f", CDTIME_T_TO_DOUBLE(now), CDTIME_T_TO_DOUBLE(wait_until));
  22. if (now >= wait_until) {
  23. - WARNING("Not sleeping because the next interval is "
  24. + WARNING("Sleeping only 2s because the next interval is "
  25. "%.3f seconds in the past!",
  26. CDTIME_T_TO_DOUBLE(now - wait_until));
  27. - wait_until = now + interval;
  28. - continue;
  29. + wait_until = now + DOUBLE_TO_CDTIME_T(2);
  30. + DEBUG("do_loop: wait_until adjusted to now+2 = %.3f", CDTIME_T_TO_DOUBLE(wait_until));
  31. }
  32. struct timespec ts_wait = CDTIME_T_TO_TIMESPEC(wait_until - now);
  33. wait_until = wait_until + interval;
  34. + DEBUG("do_loop ends: wait_until set to %.3f", CDTIME_T_TO_DOUBLE(wait_until));
  35. while ((loop == 0) && (nanosleep(&ts_wait, &ts_wait) != 0)) {
  36. if (errno != EINTR) {
  37. --- a/src/daemon/plugin.c
  38. +++ b/src/daemon/plugin.c
  39. @@ -585,10 +585,11 @@ static void *plugin_read_thread(void __a
  40. /* Check, if `rf_next_read' is in the past. */
  41. if (rf->rf_next_read < now) {
  42. - /* `rf_next_read' is in the past. Insert `now'
  43. + /* `rf_next_read' is in the past. Insert `now'+2s
  44. * so this value doesn't trail off into the
  45. * past too much. */
  46. - rf->rf_next_read = now;
  47. + rf->rf_next_read = now + DOUBLE_TO_CDTIME_T(2);
  48. + DEBUG("plugin_read_thread: Next read is in the past. Adjusted to now+2s");
  49. }
  50. DEBUG("plugin_read_thread: Next read of the `%s' plugin at %.3f.",