As for `ps`, `images`, `network ls` and `volume ls`, this makes it
possible to define a custom default format.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -186,13 +186,17 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error {
|
| 186 | 186 |
|
| 187 | 187 |
// before print to screen, make sure each container get at least one valid stat data |
| 188 | 188 |
waitFirst.Wait() |
| 189 |
- f := "table" |
|
| 190 |
- if len(opts.format) > 0 {
|
|
| 191 |
- f = opts.format |
|
| 189 |
+ format := opts.format |
|
| 190 |
+ if len(format) == 0 {
|
|
| 191 |
+ if len(dockerCli.ConfigFile().StatsFormat) > 0 {
|
|
| 192 |
+ format = dockerCli.ConfigFile().StatsFormat |
|
| 193 |
+ } else {
|
|
| 194 |
+ format = formatter.TableFormatKey |
|
| 195 |
+ } |
|
| 192 | 196 |
} |
| 193 | 197 |
statsCtx := formatter.Context{
|
| 194 | 198 |
Output: dockerCli.Out(), |
| 195 |
- Format: formatter.NewStatsFormat(f, daemonOSType), |
|
| 199 |
+ Format: formatter.NewStatsFormat(format, daemonOSType), |
|
| 196 | 200 |
} |
| 197 | 201 |
cleanScreen := func() {
|
| 198 | 202 |
if !opts.noStream {
|
| ... | ... |
@@ -28,6 +28,7 @@ type ConfigFile struct {
|
| 28 | 28 |
ImagesFormat string `json:"imagesFormat,omitempty"` |
| 29 | 29 |
NetworksFormat string `json:"networksFormat,omitempty"` |
| 30 | 30 |
VolumesFormat string `json:"volumesFormat,omitempty"` |
| 31 |
+ StatsFormat string `json:"statsFormat,omitempty"` |
|
| 31 | 32 |
DetachKeys string `json:"detachKeys,omitempty"` |
| 32 | 33 |
CredentialsStore string `json:"credsStore,omitempty"` |
| 33 | 34 |
Filename string `json:"-"` // Note: for internal use only |
| ... | ... |
@@ -123,6 +123,26 @@ falls back to the default table format. For a list of supported formatting |
| 123 | 123 |
directives, see the |
| 124 | 124 |
[**Formatting** section in the `docker ps` documentation](ps.md) |
| 125 | 125 |
|
| 126 |
+The property `imagesFormat` specifies the default format for `docker images` output. |
|
| 127 |
+When the `--format` flag is not provided with the `docker images` command, |
|
| 128 |
+Docker's client uses this property. If this property is not set, the client |
|
| 129 |
+falls back to the default table format. For a list of supported formatting |
|
| 130 |
+directives, see the [**Formatting** section in the `docker images` documentation](images.md) |
|
| 131 |
+ |
|
| 132 |
+The property `serviceInspectFormat` specifies the default format for `docker |
|
| 133 |
+service inspect` output. When the `--format` flag is not provided with the |
|
| 134 |
+`docker service inspect` command, Docker's client uses this property. If this |
|
| 135 |
+property is not set, the client falls back to the default json format. For a |
|
| 136 |
+list of supported formatting directives, see the |
|
| 137 |
+[**Formatting** section in the `docker service inspect` documentation](service_inspect.md) |
|
| 138 |
+ |
|
| 139 |
+The property `statsFormat` specifies the default format for `docker |
|
| 140 |
+stats` output. When the `--format` flag is not provided with the |
|
| 141 |
+`docker stats` command, Docker's client uses this property. If this |
|
| 142 |
+property is not set, the client falls back to the default table |
|
| 143 |
+format. For a list of supported formatting directives, see |
|
| 144 |
+[**Formatting** section in the `docker stats` documentation](stats.md) |
|
| 145 |
+ |
|
| 126 | 146 |
Once attached to a container, users detach from it and leave it running using |
| 127 | 147 |
the using `CTRL-p CTRL-q` key sequence. This detach key sequence is customizable |
| 128 | 148 |
using the `detachKeys` property. Specify a `<sequence>` value for the |
| ... | ... |
@@ -141,19 +161,6 @@ Users can override your custom or the default key sequence on a per-container |
| 141 | 141 |
basis. To do this, the user specifies the `--detach-keys` flag with the `docker |
| 142 | 142 |
attach`, `docker exec`, `docker run` or `docker start` command. |
| 143 | 143 |
|
| 144 |
-The property `imagesFormat` specifies the default format for `docker images` output. |
|
| 145 |
-When the `--format` flag is not provided with the `docker images` command, |
|
| 146 |
-Docker's client uses this property. If this property is not set, the client |
|
| 147 |
-falls back to the default table format. For a list of supported formatting |
|
| 148 |
-directives, see the [**Formatting** section in the `docker images` documentation](images.md) |
|
| 149 |
- |
|
| 150 |
-The property `serviceInspectFormat` specifies the default format for `docker |
|
| 151 |
-service inspect` output. When the `--format` flag is not provided with the |
|
| 152 |
-`docker service inspect` command, Docker's client uses this property. If this |
|
| 153 |
-property is not set, the client falls back to the default json format. For a |
|
| 154 |
-list of supported formatting directives, see the |
|
| 155 |
-[**Formatting** section in the `docker service inspect` documentation](service_inspect.md) |
|
| 156 |
- |
|
| 157 | 144 |
Following is a sample `config.json` file: |
| 158 | 145 |
|
| 159 | 146 |
{% raw %}
|
| ... | ... |
@@ -163,6 +170,7 @@ Following is a sample `config.json` file: |
| 163 | 163 |
}, |
| 164 | 164 |
"psFormat": "table {{.ID}}\\t{{.Image}}\\t{{.Command}}\\t{{.Labels}}",
|
| 165 | 165 |
"imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}",
|
| 166 |
+ "statsFormat": "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}",
|
|
| 166 | 167 |
"serviceInspectFormat": "pretty", |
| 167 | 168 |
"detachKeys": "ctrl-e,e" |
| 168 | 169 |
} |