如何从泊坞窗统计信息中找到最大内存? [英] how to find MAX memory from docker stats?

查看:113
本文介绍了如何从泊坞窗统计信息中找到最大内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 docker stats ,您可以查看容器在一段时间内的内存使用情况。

With docker stats you can see the memory usage of a container over time.

有没有办法查找运行 docker stats 时最高的内存使用价值是什么?

Is there a way to find what the highest value of memory usage was while running docker stats?

推荐答案

我从此处获取了一个采样脚本,并通过@pl_rock汇总了数据。但是要小心- sort 命令仅比较字符串值-因此结果通常是错误的(对我来说还可以)。
还请注意,Docker有时会报告错误的数字(即,分配的mem多于物理RAM)。

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).

以下是脚本:

#!/bin/bash

"$@" & # Run the given command line in the background.
pid=$!

echo "" > stats

while true; do
  sleep 1
  sample="$(ps -o rss= $pid 2> /dev/null)" || break

  docker stats --no-stream --format "{{.MemUsage}} {{.Name}} {{.Container}}" | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0 }' >> stats
done

for containerid in `awk '/.+/ { print $7 }' stats | sort | uniq`
do
    grep "$containerid" stats | sort -r -k3 | tail -n 1
    # maybe: | sort -r -k3 -h | head -n 1
    # see comment below (didnt tested)
done

这篇关于如何从泊坞窗统计信息中找到最大内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆