github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/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  ```bash
    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`](#formatting), 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  ```bash
    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` with customized format on all (Running and Stopped) containers.
    89  
    90  ```bash
    91  $ docker stats --all --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" fervent_panini 5acfcb1b4fd1 drunk_visvesvaraya big_heisenberg
    92  
    93  CONTAINER                CPU %               MEM USAGE / LIMIT
    94  fervent_panini           0.00%               56KiB / 15.57GiB
    95  5acfcb1b4fd1             0.07%               32.86MiB / 15.57GiB
    96  drunk_visvesvaraya       0.00%               0B / 0B
    97  big_heisenberg           0.00%               0B / 0B
    98  ```
    99  
   100  `drunk_visvesvaraya` and `big_heisenberg` are stopped containers in the above example.
   101  
   102  Running `docker stats` on all running containers against a Windows daemon.
   103  
   104  ```powershell
   105  PS E:\> docker stats
   106  CONTAINER ID        CPU %               PRIV WORKING SET    NET I/O             BLOCK I/O
   107  09d3bb5b1604        6.61%               38.21 MiB           17.1 kB / 7.73 kB   10.7 MB / 3.57 MB
   108  9db7aa4d986d        9.19%               38.26 MiB           15.2 kB / 7.65 kB   10.6 MB / 3.3 MB
   109  3f214c61ad1d        0.00%               28.64 MiB           64 kB / 6.84 kB     4.42 MB / 6.93 MB
   110  ```
   111  
   112  Running `docker stats` on multiple containers by name and id against a Windows daemon.
   113  
   114  ```powershell
   115  PS E:\> docker ps -a
   116  CONTAINER ID        NAME                IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   117  3f214c61ad1d        awesome_brattain    nanoserver          "cmd"               2 minutes ago       Up 2 minutes                            big_minsky
   118  9db7aa4d986d        mad_wilson          windowsservercore   "cmd"               2 minutes ago       Up 2 minutes                            mad_wilson
   119  09d3bb5b1604        fervent_panini      windowsservercore   "cmd"               2 minutes ago       Up 2 minutes                            affectionate_easley
   120  
   121  PS E:\> docker stats 3f214c61ad1d mad_wilson
   122  CONTAINER ID        NAME                CPU %               PRIV WORKING SET    NET I/O             BLOCK I/O
   123  3f214c61ad1d        awesome_brattain    0.00%               46.25 MiB           76.3 kB / 7.92 kB   10.3 MB / 14.7 MB
   124  9db7aa4d986d        mad_wilson          9.59%               40.09 MiB           27.6 kB / 8.81 kB   17 MB / 20.1 MB
   125  ```
   126  
   127  ### Formatting
   128  
   129  The formatting option (`--format`) pretty prints container output
   130  using a Go template.
   131  
   132  Valid placeholders for the Go template are listed below:
   133  
   134  Placeholder  | Description
   135  ------------ | --------------------------------------------
   136  `.Container` | Container name or ID (user input)
   137  `.Name`      | Container name
   138  `.ID`        | Container ID
   139  `.CPUPerc`   | CPU percentage
   140  `.MemUsage`  | Memory usage
   141  `.NetIO`     | Network IO
   142  `.BlockIO`   | Block IO
   143  `.MemPerc`   | Memory percentage (Not available on Windows)
   144  `.PIDs`      | Number of PIDs (Not available on Windows)
   145  
   146  
   147  When using the `--format` option, the `stats` command either
   148  outputs the data exactly as the template declares or, when using the
   149  `table` directive, includes column headers as well.
   150  
   151  The following example uses a template without headers and outputs the
   152  `Container` and `CPUPerc` entries separated by a colon (`:`) for all images:
   153  
   154  ```bash
   155  $ docker stats --format "{{.Container}}: {{.CPUPerc}}"
   156  
   157  09d3bb5b1604: 6.61%
   158  9db7aa4d986d: 9.19%
   159  3f214c61ad1d: 0.00%
   160  ```
   161  
   162  To list all containers statistics with their name, CPU percentage and memory
   163  usage in a table format you can use:
   164  
   165  ```bash
   166  $ docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
   167  
   168  CONTAINER           CPU %               PRIV WORKING SET
   169  1285939c1fd3        0.07%               796 KiB / 64 MiB
   170  9c76f7834ae2        0.07%               2.746 MiB / 64 MiB
   171  d1ea048f04e4        0.03%               4.583 MiB / 64 MiB
   172  ```
   173  
   174  The default format is as follows:
   175  
   176  On Linux:
   177  
   178      "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"
   179  
   180  On Windows:
   181  
   182      "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}"
   183