TL;DR: Run pm2 install pm2-logrotate
PM2 is a process manager for Node.js, usually used in production
Yesterday I've ran into a problem on one of the production machines that I manage. Suddenly, the database stopped working and soon I found out that I was almost out of disk space.
At first sight, I've checked my database records: all ok, as big as I was expecting.
Then, I had to start du -h
ing my largest directories to check what was taking so much space from my disk. I found the guilty one to be the ~/.pm2/logs
folder, and instantly realized that my app's logs where just stacking up there. I solved temporarily with pm2 flush
, but had to look for a way for that not to happen again.
And, then, I've found this guy: https://github.com/keymetrics/pm2-logrotate
It's as easy as running pm2 install pm2-logrotate
on your machine. Done! PM2 will start to limit its logs size, by default to 10 megabytes, but it's easily configurable with something like pm2 set pm2-logrotate:max_size 1K
. You can read more about the option here.
Top comments (4)
Let a server log errors overnight. Came back to a 35gb file. Thank you for this quick solution to fix pm2 log sizes!
definitely me right now..
Crazy, same situation.
Hello,
Hey guys, do you know if this solutions works for a windows enviroments?