Skip to content

docker stats equivalent #1546

@Chuseuiti

Description

@Chuseuiti

I took a look to the documentation but by doing:

cli=docker.from_env()

server=cli.containers.run(...)

server.stats()

Output:
<generator..>

I didnt get the expected results. I was only able to get the stats with the low level API:

client=..

sts=client.stats(container=..)

and even under that command I didnt get the CPU and Memory percentages that sudo docker stats provides.

(sudo docker stats)

ID CPU CPU% Memory Memory% ..

Could you please provide the call to obtain the CPU and memory percentages, as it is not clear to me in the documentation.

Also I tried the following equation and I didnt obtained the same percentage as docker stats:

    cpuDelta = (sts.CPUStats.CPUUsage.TotalUsage) - (previousCPU.CPUUsage.TotalUsage)

    systemDelta = (v.CPUStats.SystemUsage) - (previousSystem.CPUStats.SystemUsage)


    cpuPercent = float(cpuDelta / systemDelta) * float(len(sts.CPUStats.CPUUsage.PercpuUsage)) * 100.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions