github.com/docker/docker-ce@v17.12.1-ce-rc2+incompatible/components/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  <!-- This file is maintained within the docker/cli GitHub
     8       repository at https://github.com/docker/cli/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # stats
    17  
    18  ```markdown
    19  Usage:  docker stats [OPTIONS] [CONTAINER...]
    20  
    21  Display a live stream of container(s) resource usage statistics
    22  
    23  Options:
    24    -a, --all             Show all containers (default shows just running)
    25        --format string   Pretty-print images using a Go template
    26        --help            Print usage
    27        --no-stream       Disable streaming stats and only pull the first result
    28        --no-trunc        Don't truncate output
    29  ```
    30  
    31  ## Description
    32  
    33  The `docker stats` command returns a live data stream for running containers. To limit data to one or more specific containers, specify a list of container names or ids separated by a space. You can specify a stopped container but stopped containers do not return any data.
    34  
    35  If you want more detailed information about a container's resource usage, use the `/containers/(id)/stats` API endpoint.
    36  
    37  > **Note**: On Linux, the Docker CLI reports memory usage by subtracting page cache usage from the total memory usage. The API does not perform such a calculation but rather provides the total memory usage and the amount from the page cache so that clients can use the data as needed.
    38  
    39  ## Examples
    40  
    41  Running `docker stats` on all running containers against a Linux daemon.
    42  
    43  ```bash
    44  $ docker stats
    45  
    46  CONTAINER ID        NAME                                    CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
    47  b95a83497c91        awesome_brattain                        0.28%               5.629MiB / 1.952GiB   0.28%               916B / 0B           147kB / 0B          9
    48  67b2525d8ad1        foobar                                  0.00%               1.727MiB / 1.952GiB   0.09%               2.48kB / 0B         4.11MB / 0B         2
    49  e5c383697914        test-1951.1.kay7x1lh1twk9c0oig50sd5tr   0.00%               196KiB / 1.952GiB     0.01%               71.2kB / 0B         770kB / 0B          1
    50  4bda148efbc0        random.1.vnc8on831idyr42slu578u3cr      0.00%               1.672MiB / 1.952GiB   0.08%               110kB / 0B          578kB / 0B          2
    51  ```
    52  
    53  Running `docker stats` on multiple containers by name and id against a Linux daemon.
    54  
    55  ```bash
    56  $ docker stats awesome_brattain 67b2525d8ad1
    57  
    58  CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
    59  b95a83497c91        awesome_brattain    0.28%               5.629MiB / 1.952GiB   0.28%               916B / 0B           147kB / 0B          9
    60  67b2525d8ad1        foobar              0.00%               1.727MiB / 1.952GiB   0.09%               2.48kB / 0B         4.11MB / 0B         2
    61  ```
    62  
    63  Running `docker stats` with customized format on all (Running and Stopped) containers.
    64  
    65  ```bash
    66  $ docker stats --all --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" fervent_panini 5acfcb1b4fd1 drunk_visvesvaraya big_heisenberg
    67  
    68  CONTAINER                CPU %               MEM USAGE / LIMIT
    69  fervent_panini           0.00%               56KiB / 15.57GiB
    70  5acfcb1b4fd1             0.07%               32.86MiB / 15.57GiB
    71  drunk_visvesvaraya       0.00%               0B / 0B
    72  big_heisenberg           0.00%               0B / 0B
    73  ```
    74  
    75  `drunk_visvesvaraya` and `big_heisenberg` are stopped containers in the above example.
    76  
    77  Running `docker stats` on all running containers against a Windows daemon.
    78  
    79  ```powershell
    80  PS E:\> docker stats
    81  CONTAINER ID        CPU %               PRIV WORKING SET    NET I/O             BLOCK I/O
    82  09d3bb5b1604        6.61%               38.21 MiB           17.1 kB / 7.73 kB   10.7 MB / 3.57 MB
    83  9db7aa4d986d        9.19%               38.26 MiB           15.2 kB / 7.65 kB   10.6 MB / 3.3 MB
    84  3f214c61ad1d        0.00%               28.64 MiB           64 kB / 6.84 kB     4.42 MB / 6.93 MB
    85  ```
    86  
    87  Running `docker stats` on multiple containers by name and id against a Windows daemon.
    88  
    89  ```powershell
    90  PS E:\> docker ps -a
    91  CONTAINER ID        NAME                IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    92  3f214c61ad1d        awesome_brattain    nanoserver          "cmd"               2 minutes ago       Up 2 minutes                            big_minsky
    93  9db7aa4d986d        mad_wilson          windowsservercore   "cmd"               2 minutes ago       Up 2 minutes                            mad_wilson
    94  09d3bb5b1604        fervent_panini      windowsservercore   "cmd"               2 minutes ago       Up 2 minutes                            affectionate_easley
    95  
    96  PS E:\> docker stats 3f214c61ad1d mad_wilson
    97  CONTAINER ID        NAME                CPU %               PRIV WORKING SET    NET I/O             BLOCK I/O
    98  3f214c61ad1d        awesome_brattain    0.00%               46.25 MiB           76.3 kB / 7.92 kB   10.3 MB / 14.7 MB
    99  9db7aa4d986d        mad_wilson          9.59%               40.09 MiB           27.6 kB / 8.81 kB   17 MB / 20.1 MB
   100  ```
   101  
   102  ### Formatting
   103  
   104  The formatting option (`--format`) pretty prints container output
   105  using a Go template.
   106  
   107  Valid placeholders for the Go template are listed below:
   108  
   109  Placeholder  | Description
   110  ------------ | --------------------------------------------
   111  `.Container` | Container name or ID (user input)
   112  `.Name`      | Container name
   113  `.ID`        | Container ID
   114  `.CPUPerc`   | CPU percentage
   115  `.MemUsage`  | Memory usage
   116  `.NetIO`     | Network IO
   117  `.BlockIO`   | Block IO
   118  `.MemPerc`   | Memory percentage (Not available on Windows)
   119  `.PIDs`      | Number of PIDs (Not available on Windows)
   120  
   121  
   122  When using the `--format` option, the `stats` command either
   123  outputs the data exactly as the template declares or, when using the
   124  `table` directive, includes column headers as well.
   125  
   126  The following example uses a template without headers and outputs the
   127  `Container` and `CPUPerc` entries separated by a colon for all images:
   128  
   129  ```bash
   130  $ docker stats --format "{{.Container}}: {{.CPUPerc}}"
   131  
   132  09d3bb5b1604: 6.61%
   133  9db7aa4d986d: 9.19%
   134  3f214c61ad1d: 0.00%
   135  ```
   136  
   137  To list all containers statistics with their name, CPU percentage and memory
   138  usage in a table format you can use:
   139  
   140  ```bash
   141  $ docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
   142  
   143  CONTAINER           CPU %               PRIV WORKING SET
   144  1285939c1fd3        0.07%               796 KiB / 64 MiB
   145  9c76f7834ae2        0.07%               2.746 MiB / 64 MiB
   146  d1ea048f04e4        0.03%               4.583 MiB / 64 MiB
   147  ```
   148  
   149  The default format is as follows:
   150  
   151  On Linux:
   152  
   153      "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"
   154  
   155  On Windows:
   156  
   157      "table {{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}"
   158  
   159  
   160  > **Note**: On Docker 17.09 and older, the `{{.Container}}` column was used, in
   161  > stead of `{{.ID}}\t{{.Name}}`.