Log rotation for telegraf file output

4.6k views Asked by At

I am going through https://github.com/influxdata/telegraf/tree/master/plugins/outputs/file

But there is no option to rotate the log file.
This is causing huge log files to be created which have to be deleted manually.

Once deleted manually, telegraf does not recreate that file and only option is to restart telegraf.

I do not want to rotate the log file with a cron job because telegraf may be in the middle of doing something with the log file and as per our use-case, we need to have last 10 minutes of telegraf output with metrics being sent by telegraf every minute.

Seems like someone started in this direction, but never completed it. https://github.com/influxdata/telegraf/issues/1550

1

There are 1 answers

0
Hieu Huynh On

Please update telegraf to newer version 1.12.x, they support rotation on both output file plugin and agent log

[[outputs.file]]
  files = ["stdout", "/tmp/metrics.out"]

  rotation_interval = "24h"
  rotation_max_archives = 10

  data_format = "influx" 
[agent]
  ...
  debug = false
  quiet = false
  logfile = "/var/log/telegraf/telegraf.log"
  logfile_rotation_interval = "24h"
  logfile_rotation_max_archives = -1
  ...