Premium Hosted Website & Server Monitoring Tool.

(Sysadmin / Devops blog)

visit our website

Blog   >   MongoDB   >   MongoDB log rotations can cause crashes

MongoDB log rotations can cause crashes

mongodb-log-rotations-can-cause-crashes

Logging is great for debugging but you have to deal with periodically rotating the files so they don’t become massive. We pipe all our logs into Papertrail so we can search them, doing log rotations every 12 hours for most things.

The ability for MongoDB to log to syslog was added in the 2.2 release so you can allow your system to deal with this. We log to a separate file and use a cron job to rotate the logs instead. The documentation recommends you do this by sending a SIGUSR1 flag to the Unix process. Doing this can cause the Mongo process to hang or crash.

Until this bug is fixed, you should use the mongo console to run the logRotate command:

mongo admin --eval "printjson(db.runCommand(\"logRotate\"))" --port 27017

This has the same effect but will avoid the crashing bug. It applies to both mongod and mongos.

  • http://twitter.com/xXstandstillXx Machika Kara Kuro (@xXstandstillXx)

    Currently i am truncating my mongo logs every few hours, i am thinking about using logstash

  • Atziel Delavi

    Send MongoDb logs to Syslog and you only need to reload the syslog process. Works nicely!