Pm2 logs with huge size using pm2-logrotate
Asked Answered
S

1

6

I'm having troubles with pm2.

I'm using a module called pm2-logrotate but the logs have a huge gize like 1.7G and don't respect my configuration which is

== pm2-logrotate ==
┌────────────────┬───────────────┐
│ key            │ value         │
├────────────────┼───────────────┤
│ compress       │ true          │
│ rotateInterval │ * * */1 * * * │
│ max_size       │ 10M           │
│ retain         │ 1             │
│ rotateModule   │ true          │
│ workerInterval │ 30            │
└────────────────┴───────────────┘

So what can I do to pm2 can delete the old logs and dont start crushing my machine with a huge amount of data?

Suttles answered 2/1, 2018 at 9:28 Comment(1)
I had this same problem, the solution for me was run pm2 flush first, and then install and configure the pm2-logrotateDiscomfort
C
3

I had this problem too. I think there's currently a bug in pm2-logrotate where the workerInterval option is ignored, and it only rotates according to the rotateInterval option (i.e. once per day by default). And that means that the files can get much bigger than the size you specified with the max_size option. See options here.

I "solved" it by setting the rotateInterval option to every 30 mins instead of the default of once per day. Here's the command:

pm2 set pm2-logrotate:rotateInterval '*/30 * * * *'

The problem with this is that it means your logs will rotate every 30 mins no matter what size they are. Another temporary solution would be to run pm2 flush (which deletes all logs) with crontab. First run crontab -e in your terminal, and then add this line to the file:

*/30 * * * * pm2 flush

You can also flush a specific app with pm2 flush your_app_name if you've got a particular app that produces a lot of logs. If you're not good at remembering how cron timing syntax works (like me), you can use this site.

Cere answered 7/4, 2021 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.