I tried few things but still not able to rotate haproxy logs efficiently. I need to rotate logs when log files crosses 500 MB size. Considering haproxy is serving large no. of static tcp connections, I can not restart haproxy process though a reload is doable. Daily haproxy log file size normally crosses 3 GB on my machine. Here's sample from one of newer machine where log file size is growing beyond limit set:
ubuntu@server:/mnt/log/haproxy$ ls -lsh total 4.3G 85M -rw-r----- 1 syslog adm 85M Jun 2 07:13 haproxy.log 2.9G -rw-r----- 1 syslog adm 2.9G Jun 2 06:37 haproxy.log.1 460M -rw-r----- 1 syslog adm 460M Jun 1 06:32 haproxy.log.2.gz 469M -rw-r----- 1 syslog adm 469M May 31 06:42 haproxy.log.3.gz 384M -rw-r----- 1 syslog adm 384M May 30 06:49 haproxy.log.4.gz ubuntu@server:/mnt/log/haproxy$ cat /etc/logrotate.d/haproxy /mnt/log/haproxy/haproxy.log { missingok copytruncate notifempty rotate 50 size 500M compress delaycompress }
Logrotate does not continuously monitor your log files. Normally logrotate is run as part of the daily cron job specified in
/etc/crontab
which runs the scripts in /etc/cron.daily
. As such it is working as expected in that when it runs, if the files are >500M and they are rotated.
You will need to run logrotate more frequently if you want to catch the log files closer to 500M. You could do this by copying the
/etc/cron.daily/logrotate
script to /etc/cron.hourly/logrotate
.
This will also mean that other log files may be rotated early too.
Yes, if you do it that way. It would be more sane to add an hourly cronjob to just
logrotate /etc/logrotate.d/haproxy
0 comments: