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 docker stats
?
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 docker stats
?
you can use command:
It will give highest memory by container.
Let me Explain command:
I took a sampling script from here and aggregated data by @pl_rock. But be careful - the
sort
command only compares string values - so the results are usually wrong (but ok for me). Also mind that docker is sometimes reporting wrong numbers (ie. more allocated mem than physical RAM).Here is the script:
In my case I wanted to monitor a docker container which runs tests for my web application. The test suite is pretty big, they include 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 the later analysis.
I ended up with a modified and simplified version of the Keiran's solution:
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
If you need to find the peak usage you are better off requesting the
.MemPerc
option and calculating based on the total memory (unless you restricted the memory available to the container)..MemUsage
has units which change during the life of the container which mess with the result.You can stream an ongoing log to a file (or script).
To get just the max memory as originally requested:
And then you can ask the system for its total RAM (again assuming you didn't limit the RAM available to docker) and calculate:
You would need to know how long the container is going to run when using timeout as above, but if
docker stats
was run without this in background submitted by a script it could kill it once the container completed....
This command allows you to generate a time-series of the cpu/memory load:
Note that it pipes into gzip. In this form you get ~2 rows per second so the file would get large rapidly if you don't.
I'd advise this for benchmarking and trouble shooting rather than use on production containers