telegraf icon indicating copy to clipboard operation
telegraf copied to clipboard

[Feature Request] Reopen Telegraf log by SIGHUP (without a restart)

Open vassilevsky opened this issue 7 years ago • 1 comments

Feature Request

Opening a feature request kicks off a discussion.

Proposal:

Telegraf must be able to reopen log device by a signal.

Current behavior:

Telegraf opens a log device and logs to it forever. In order to rotate the log, one must restart Telegraf. This leads to a loss of aggregated metrics.

Desired behavior:

Telegraf reopens the log when it receives a HUP signal. To rotate the log, one can do the following:

  1. Rename the currently open Telegraf log file. Telegraf keeps writing to the renamed file.
  2. Send a HUP signal to Telegraf process. Telegraf reopens the "original" log file and starts writing to it.
  3. The previously renamed log file can be archived.

Example solution: https://github.com/client9/reopen

The signal can be different, as SIGHUP seems to be reserved for config reload.

Use case: [Why is this important (helps with prioritizing requests)]

Rotate Telegraf log without losing metrics.

🙏

vassilevsky avatar Dec 10 '18 12:12 vassilevsky

The logrotate configuration we have uses copytruncate:

   copytruncate
         Truncate the original log file to zero size in place after  cre‐
         ating  a copy, instead of moving the old log file and optionally
         creating a new one.  It can be used when some program cannot  be
         told  to  close  its  logfile  and  thus  might continue writing
         (appending) to the previous log file forever.  Note  that  there
         is a very small time slice between copying the file and truncat‐
         ing it, so some logging data might be lost. When this option is
         used, the create option will have no effect, as the old log file
         stays in place.

Still, I would prefer to reopen the file on SIGHUP as well a dedicated signal for only log reloading.

danielnelson avatar Dec 12 '18 03:12 danielnelson