def test_docker_parse_container_mem_docker_plugin_cgroupv2_with_limit(): result = parse_docker_container_mem(PLUGIN_OUTPUT_CGROUPV2_LIMIT) assert result == {"MemFree": 55504896, "MemTotal": 57671680} # make sure docker stats result is the same: assert (result["MemTotal"]) / 1024 / 1024 == 55 assert round( (result["MemTotal"] - result["MemFree"]) / 1024 / 10.24) / 100 == 2.07
def test_parse_container_mem_docker_plugin_with_limit(): """ same as above, but with a 500MiB memory limit set via `-m` on `docker run` """ result = parse_docker_container_mem(PLUGIN_OUTPUT_MEM_LIMIT) assert result == {'MemFree': 119451648, 'MemTotal': 524288000} # compare to output of docker stats: assert round(result['MemTotal'] / 1024 / 1024) == 500 assert round((result['MemTotal'] - result['MemFree']) / 1024 / 102.4) / 10 == 386.1
def test_docker_parse_container_mem_docker_plugin_cgroupv2(): """ data fetched with mk_docker.py may look different depending on the cgroup version used on the host. """ result = parse_docker_container_mem(PLUGIN_OUTPUT_CGROUPV2) assert result == {'MemFree': 16564215808, 'MemTotal': 16591540224} # make sure docker stats result is the same: assert round((result['MemTotal'] - result['MemFree']) / 1024 / 10.24) / 100 == 26.06
def test_parse_container_mem_docker_plugin(): """ see if the output returned from mk_docker.py on a host with cgroup v1 can be parsed corretly """ result = parse_docker_container_mem(PLUGIN_OUTPUT_MEM_NO_LIMIT) assert result == {'MemFree': 3611148288, 'MemTotal': 4667232256} # compare to output of docker stats: assert round(result['MemTotal'] / 1024 / 1024 / 1.024) / 1000 == 4.347 assert round((result['MemTotal'] - result['MemFree']) / 1024 / 1024) == 1007