mqtt-tools / mqttwarn

A highly configurable MQTT message router, where the routing targets are notification plugins, primarily written in Python.
https://mqttwarn.readthedocs.io/
Eclipse Public License 2.0
955 stars 183 forks source link

Adjust logging configuration for Docker container #355

Open psyciknz opened 5 years ago

psyciknz commented 5 years ago

Not an issue, but a note worth looking at for those with Docker.

By default, docker does not manage it's own logs for each container. And defaults to json-file. When my system ground to a halt, I found the mqttwarn docker log (since I send to stream), sitting at 7.2gb.

The answer (for me), was to configure the container, or docker service to set a file size limit on the log file: https://docs.docker.com/config/containers/logging/json-file/

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
jwyse commented 5 years ago

Thanks for sharing this. Even though it's not specific to mqttwarn, and not a bug/issue, I found it helpful. I just freed about 9 GB of logs from various containers.

I initially overlooked this part, which led to some head-scratching: (emphasis mine)

Restart Docker for the changes to take effect for newly created containers. Existing containers do not use the new logging configuration.

So you have to restart the docker service AND recreate the container, for this to go into effect.

amotl commented 3 years ago

Dear @psyciknz,

also thanks for sharing this. Do you see any chance to submit a patch to add this to the documentation at [1] using appropriate command line options like --log-opt max-size=10m?

With kind regards, Andreas.

[1] https://github.com/jpmens/mqttwarn/blob/main/DOCKER.md