我从docker-java API开始。我从测试资料中读到了一些例子。
我从java api生成了一个容器。之后,我想要监控这个容器。换句话说,在Java API中翻译docker stats myContainer
。
当我从shell获得docker stats container1
时,我得到了这个结果:
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
container1 0.00% 92 KiB / 995.9 MiB 0.01% 648 B / 648 B 0 B / 0 B 1
但是,当我尝试从docker-Java API中检索这些结果时,如下所示:
List<Container> containers = dockerClient.listContainersCmd().exec();
for(Container container: containers){
InspectContainerResponse response= dockerClient.inspectContainerCmd(container.getId()).exec();
System.out.println(response.getHostConfig());
}
我获得:
com.github.dockerjava.api.model.HostConfig@1992eaf4 [结合=,blkioWeight = 0,blkioWeightDevice =,blkioDeviceReadBps =,blkioDeviceReadIOps =,blkioDeviceWriteBps =,blkioDeviceWriteIOps =,memorySwappiness = -1,capAdd =,capDrop =, containerIDFile =, cpuPeriod = 0,的 cpuShares = 0,的 cpuQuota = 0,的 cpusetC 脓=,cpusetMems =,设备= {},DNS = {},dnsSearch = {},extraHosts =,=链接,logConfig = com.github.dockerjava.api.model.LogConfig @ f74e835,lxcConf =,存储器 = 0 , memorySwap = 0,的 memoryReservation = 0,kernelMemory = 0,网络模式=默认,oomKillDisable =假,oomScoreAdj =假,portBindings = {80 / TCP = [Lcom.github .dockerjava.api.model.Ports $绑定; @ 21d8bcbe},特权=假,publishAllPorts =假,readonlyRootfs =假,restartPolicy =无,ulimits =,= volumesFrom,pidMode =,= securityOpts,cgroupParent =,= volumeDriver,shmSize = 67108864]
所有属性都是0 !!!有人可以向我解释我如何能够检索与docker stats myContainer
相同的结果?