docker stats 是怎么算出来的,我倒是知道了,参考:[docker stats Description](https://link.segmentfault.com/?enc=az6KlnBvulIMT7Qzyl7sFQ%3D%3D.xStRthia49BmUzThN1Cako6lllDKZOTXSrR7yZDRGnPjwGJfvxisJVWX7OoV9k7zy5H%2FAWH2UqsbzeV01E%2BvZph0edOCpHGRkKuGQHIyyPY%3D) > On Linux, the Docker CLI reports memory usage by subtracting cache usage > from the total memory usage. The API does not perform such a calculation but > rather provides the total memory usage and the amount from the cache so that > clients can use the data as needed. The cache usage is defined as the value > of `total_inactive_file` field in the `memory.stat` file on cgroup v1 hosts. > 在 Linux 上,Docker CLI 通过从总内存使用量中减去缓存使用量来报告内存使用量。 API > 不执行此类计算,而是提供总内存使用量和缓存量,以便客户端可以根据需要使用数据。缓存使用情况定义为 cgroup v1 主机上 `memory.stat` > 文件中 `total_inactive_file` 字段的值。 > > On Docker 19.03 and older, the cache usage was defined as the value of > `cache` field. On cgroup v2 hosts, the cache usage is defined as the value > of `inactive_file` field. > 在 Docker 19.03 及更早版本中,缓存使用情况定义为 `cache` 字段的值。在 cgroup v2 主机上,缓存使用情况定义为 > `inactive_file` 字段的值。 因为我的主机是 cgroupv2 的,所以要想和 docker stats 一样,那就要 usage 减去 inactive_file float(container_stats['memory_stats']['usage'])-float(container_stats['memory_stats']['stats']['inactive_file']) * * * 至于第二个问题「问题二:为什么 htop 和 docker stats 的结果不一样」,我还得研究研究