With docker stats
you can see the memory usage of a container over time.
Is there a way to find what the highest value of memory usage was while running
In my case I wanted to monitor a docker container which runs tests for my web application. The test suite is pretty big, it includes javascript tests in a real browser and consume significant amount of both, memory and time.
Ideally, I wanted to watch the current memory usage real time, but to also keep the history for later analysis.
I ended up using a modified and simplified version of the Keiran's solution:
CONTAINER=$(docker ps -q -f name=CONTAINER_NAME)
FORMAT='{{.MemPerc}}\t{{.MemUsage}}\t{{.Name}}'
docker stats --format $FORMAT $CONTAINER | sed -u 's/\x1b\[[0-9;]*[a-zA-Z]//g' | tee stats
Notes:
CONTAINER=$(docker ps -q -f name=NAME) #
find container by name, but there are other optionsFORMAT='{{.MemPerc}} ...}} #
MemPerc goes first (for sorting); otherwise you can be creativesed -u #
the -u
flag is important, it turns off buffering| sed -u 's/\x1b\[[0-9;]*[a-zA-Z]//g' #
removes ANSI escape sequences| tee stats #
not only show real time, but also write into the stats filesort -n stats | tail