github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/docs/reference/commandline/stats.md (about)

     1  ---
     2  title: "stats"
     3  description: "The stats command description and usage"
     4  keywords: "container, resource, statistics"
     5  ---
     6  
     7  # stats
     8  
     9  ```markdown
    10  Usage:  docker stats [OPTIONS] [CONTAINER...]
    11  
    12  Display a live stream of container(s) resource usage statistics
    13  
    14  Options:
    15    -a, --all             Show all containers (default shows just running)
    16        --format string   Pretty-print images using a Go template
    17        --help            Print usage
    18        --no-stream       Disable streaming stats and only pull the first result
    19        --no-trunc        Don't truncate output
    20  ```
    21  
    22  ## Description
    23  
    24  The `docker stats` command returns a live data stream for running containers. To
    25  limit data to one or more specific containers, specify a list of container names
    26  or ids separated by a space. You can specify a stopped container but stopped
    27  containers do not return any data.
    28  
    29  If you need more detailed information about a container's resource usage, use
    30  the `/containers/(id)/stats` API endpoint.
    31  
    32  > **Note**
    33  >
    34  > On Linux, the Docker CLI reports memory usage by subtracting cache usage from
    35  > the total memory usage. The API does not perform such a calculation but rather
    36  > provides the total memory usage and the amount from the cache so that clients
    37  > can use the data as needed. The cache usage is defined as the value of
    38  > `total_inactive_file` field in the `memory.stat` file on cgroup v1 hosts.
    39  >
    40  > On Docker 19.03 and older, the cache usage was defined as the value of `cache`
    41  > field. On cgroup v2 hosts, the cache usage is defined as the value of
    42  > `inactive_file` field.
    43  
    44  > **Note**
    45  >
    46  > The `PIDS` column contains the number of processes and kernel threads created
    47  > by that container. Threads is the term used by Linux kernel. Other equivalent
    48  > terms are "lightweight process" or "kernel task", etc. A large number in the
    49  > `PIDS` column combined with a small number of processes (as reported by `ps`
    50  > or `top`) may indicate that something in the container is creating many threads.
    51  
    52  ## Examples
    53  
    54  Running `docker stats` on all running containers against a Linux daemon.
    55  
    56  ```console
    57  $ docker stats
    58  
    59  CONTAINER ID        NAME                                    CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
    60  b95a83497c91        awesome_brattain                        0.28%               5.629MiB / 1.952GiB   0.28%               916B / 0B           147kB / 0B          9
    61  67b2525d8ad1        foobar                                  0.00%               1.727MiB / 1.952GiB   0.09%               2.48kB / 0B         4.11MB / 0B         2
    62  e5c383697914        test-1951.1.kay7x1lh1twk9c0oig50sd5tr   0.00%               196KiB / 1.952GiB     0.01%               71.2kB / 0B         770kB / 0B          1
    63  4bda148efbc0        random.1.vnc8on831idyr42slu578u3cr      0.00%               1.672MiB / 1.952GiB   0.08%               110kB / 0B          578kB / 0B          2
    64  ```
    65  
    66  If you don't [specify a format string using `--format`](#format), the
    67  following columns are shown.
    68  
    69  | Column name               | Description                                                                                   |
    70  |---------------------------|-----------------------------------------------------------------------------------------------|
    71  | `CONTAINER ID` and `Name` | the ID and name of the container                                                              |
    72  | `CPU %` and `MEM %`       | the percentage of the host's CPU and memory the container is using                            |
    73  | `MEM USAGE / LIMIT`       | the total memory the container is using, and the total amount of memory it is allowed to use  |
    74  | `NET I/O`                 | The amount of data the container has sent and received over its network interface             |
    75  | `BLOCK I/O`               | The amount of data the container has read to and written from block devices on the host       |
    76  | `PIDs`                    | the number of processes or threads the container has created                                  |
    77  
    78  Running `docker stats` on multiple containers by name and id against a Linux daemon.
    79  
    80  ```console
    81  $ docker stats awesome_brattain 67b2525d8ad1
    82  
    83  CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
    84  b95a83497c91        awesome_brattain    0.28%               5.629MiB / 1.952GiB   0.28%               916B / 0B           147kB / 0B          9
    85  67b2525d8ad1        foobar              0.00%               1.727MiB / 1.952GiB   0.09%               2.48kB / 0B         4.11MB / 0B         2
    86  ```
    87  
    88  Running `docker stats` on container with name nginx and getting output in `json` format.
    89  
    90  ```console
    91  $ docker stats nginx --no-stream --format "{{ json . }}"
    92  {"BlockIO":"0B / 13.3kB","CPUPerc":"0.03%","Container":"nginx","ID":"ed37317fbf42","MemPerc":"0.24%","MemUsage":"2.352MiB / 982.5MiB","Name":"nginx","NetIO":"539kB / 606kB","PIDs":"2"}
    93  ```
    94  
    95  Running `docker stats` with customized format on all (Running and Stopped) containers.
    96  
    97  ```console
    98  $ docker stats --all --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" fervent_panini 5acfcb1b4fd1 drunk_visvesvaraya big_heisenberg
    99  
   100  CONTAINER                CPU %               MEM USAGE / LIMIT
   101  fervent_panini           0.00%               56KiB / 15.57GiB
   102  5acfcb1b4fd1             0.07%               32.86MiB / 15.57GiB
   103  drunk_visvesvaraya       0.00%               0B / 0B
   104  big_heisenberg           0.00%               0B / 0B
   105  ```
   106  
   107  `drunk_visvesvaraya` and `big_heisenberg` are stopped containers in the above example.
   108  
   109  Running `docker stats` on all running containers against a Windows daemon.
   110  
   111  ```powershell
   112  PS E:\> docker stats
   113  CONTAINER ID        CPU %               PRIV WORKING SET    NET I/O             BLOCK I/O
   114  09d3bb5b1604        6.61%               38.21 MiB           17.1 kB / 7.73 kB   10.7 MB / 3.57 MB
   115  9db7aa4d986d        9.19%               38.26 MiB           15.2 kB / 7.65 kB   10.6 MB / 3.3 MB
   116  3f214c61ad1d        0.00%               28.64 MiB           64 kB / 6.84 kB     4.42 MB / 6.93 MB
   117  ```
   118  
   119  Running `docker stats` on multiple containers by name and id against a Windows daemon.
   120  
   121  ```powershell
   122  PS E:\> docker ps -a
   123  CONTAINER ID        NAME                IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   124  3f214c61ad1d        awesome_brattain    nanoserver          "cmd"               2 minutes ago       Up 2 minutes                            big_minsky
   125  9db7aa4d986d        mad_wilson          windowsservercore   "cmd"               2 minutes ago       Up 2 minutes                            mad_wilson
   126  09d3bb5b1604        fervent_panini      windowsservercore   "cmd"               2 minutes ago       Up 2 minutes                            affectionate_easley
   127  
   128  PS E:\> docker stats 3f214c61ad1d mad_wilson
   129  CONTAINER ID        NAME                CPU %               PRIV WORKING SET    NET I/O             BLOCK I/O
   130  3f214c61ad1d        awesome_brattain    0.00%               46.25 MiB           76.3 kB / 7.92 kB   10.3 MB / 14.7 MB
   131  9db7aa4d986d        mad_wilson          9.59%               40.09 MiB           27.6 kB / 8.81 kB   17 MB / 20.1 MB
   132  ```
   133  
   134  ### <a name="format"></a> Format the output (--format)
   135  
   136  The formatting option (`--format`) pretty prints container output
   137  using a Go template.
   138  
   139  Valid placeholders for the Go template are listed below:
   140  
   141  | Placeholder  | Description                                  |
   142  |--------------|----------------------------------------------|
   143  | `.Container` | Container name or ID (user input)            |
   144  | `.Name`      | Container name                               |
   145  | `.ID`        | Container ID                                 |
   146  | `.CPUPerc`   | CPU percentage                               |
   147  | `.MemUsage`  | Memory usage                                 |
   148  | `.NetIO`     | Network IO                                   |
   149  | `.BlockIO`   | Block IO                                     |
   150  | `.MemPerc`   | Memory percentage (Not available on Windows) |
   151  | `.PIDs`      | Number of PIDs (Not available on Windows)    |
   152  
   153  When using the `--format` option, the `stats` command either
   154  outputs the data exactly as the template declares or, when using the
   155  `table` directive, includes column headers as well.
   156  
   157  The following example uses a template without headers and outputs the
   158  `Container` and `CPUPerc` entries separated by a colon (`:`) for all images:
   159  
   160  ```console
   161  $ docker stats --format "{{.Container}}: {{.CPUPerc}}"
   162  
   163  09d3bb5b1604: 6.61%
   164  9db7aa4d986d: 9.19%
   165  3f214c61ad1d: 0.00%
   166  ```
   167  
   168  To list all containers statistics with their name, CPU percentage and memory
   169  usage in a table format you can use:
   170  
   171  ```console
   172  $ docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
   173  
   174  CONTAINER           CPU %               PRIV WORKING SET
   175  1285939c1fd3        0.07%               796 KiB / 64 MiB
   176  9c76f7834ae2        0.07%               2.746 MiB / 64 MiB
   177  d1ea048f04e4        0.03%               4.583 MiB / 64 MiB
   178  ```
   179  
   180  The default format is as follows:
   181  
   182  On Linux:
   183  
   184      "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"
   185  
   186  On Windows:
   187  
   188      "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}"
   189