Exporting containers resource usage data to a file for a later debugging session is a good thing to have, as you don’t want to get SSH timeout-ed. So, here’s how to export Docker containers CPU, memory, Disk I/O, PIDs and such to a file.
Prerequisites
- Docker
Solution
Step 1. Just run the following command to export all running containers resource usage in a json
format:
docker stats --no-stream --format "{{ json . }}" > containers-stats.json
Note: This command will result only in pulling the first result. However, you could format and filter which resources to be displayed to your liking.
Step 2. Move the file out of the remote server for a possible debugging session.
Conclusion
In case you face any issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.