Moby: Proposal: Docker stats to show names instead of IDs

Created on 5 Mar 2016  ·  30Comments  ·  Source: moby/moby

I've never found docker stats useful by itself and always amended it with docker stats $(docker ps --format={{.Names}})

What do you think about showing names by default?

arecli kinenhancement statuclaimed statuneeds-attention

Most helpful comment

Every time I use docker stats, I have to use docker stats $(docker ps --format={{.Names}}), otherwise, I have totally no idea which container is which. And I don't think docker stats $(docker ps --format={{.Names}}) is the solution, because it's static container list. I have to stop and rerun this command if I remove a container, or run a new container.

It make more sense if there is a name column in the docker stats by default.

All 30 comments

@omercnet what do you use it for ? Doesdocker stats $(docker ps --format={{.Names}}) fulfill your purpose ?
I am thinking what's the strong reason to add name in docker stats?

I use it for general monitoring of stats while running/testing, I can't tell which container is which just based on IDs, that's what names are for

I originally was looking maybe adding --names or something like that to stats

Aside from when running a single container (in which case it doesn't matter), is there any use case for showing just IDs ?

IIRC, currently it shows what you "requested", i.e. docker stats 39b69226f9d7 will show the _id_, whereas docker stats foobar shows the _name_ of the container. Given that docker ps shows both container _name_ and _id_ (in separate columns), I can see it being consistent to show both. Ideally (but possibly a separate feature request), add a --format flag, so that users can define which columns to include.

I'm +1 for improving this, but open to additional suggestions / thoughts

@thaJeztah you're right, that's why the I added $(docker ps --format={{.Names}}) so I would pass the names to docker stats

so perhaps only in cases when someone runs docker stats without any parameters it would display both, and if the user specifies an ID(s) or Name(s) it would display just those ? Just like docker ps adds NAMES at the end

I would like to work on this as my first assignment.

As far as I understand, showing both container ID and name for both cases where we pass an argument to command or without one, would be consistent, in that case users will also be having option to include whatever they want. Please let me know, if this is the scope and if I can go ahead and work on it.

Thanks.

@gigidwan sounds good to me (other maintainers may have different thoughts, but can comment on the PR once it's up). Thanks in advance for working on it!

@thaJeztah Thanks, so I started working on a PR for this.. just to clarify my understanding I would like to share the output here..

# docker stats
CONTAINER_ID        NAMES               CPU %               MEM USAGE / LIMIT     MEM %               NET I/O               BLOCK I/O           PIDS
ab4c4a246389        elated_mcnulty      0.00%               4.87 MB / 2.099 GB    0.23%               1.366 kB / 1.108 kB   4.37 MB / 0 B       0
a2ccc83eb793        69b4eb4a3927        0.00%               847.9 kB / 2.099 GB   0.04%               2.056 kB / 1.108 kB   770 kB / 0 B        0

And when an argument is passed

# docker stats elated_mcnulty
CONTAINER_ID                                                       NAMES               CPU %               MEM USAGE / LIMIT    MEM %               NET I/O               BLOCK I/O           PIDS
ab4c4a246389444d475f2ed3c49b391601a6f185e7342931658431566200825a   elated_mcnulty     0.00%               4.87 MB / 2.099 GB   0.23%               1.366 kB / 1.108 kB   4.37 MB / 0B       0

so, my confusion here is regarding the ID length, I believe it should be same in both the cases, but what length it should be.. or are we planning to show the length which user specifies when he is passing container ID as an argument..

Can you please clear my doubt here, so I would go ahead accordingly.

@gigidwan I think we should show the truncated ID by default (I think we use 12 characters everywhere, see https://github.com/docker/docker/blob/160abfbeeaa20314d5d971061d3bad7aaf87e66c/integration-cli/docker_cli_stats_test.go#L61, and https://github.com/docker/docker/blob/fff1511c56e35cf5230d05af2282d31d23a31dc0/docs/admin/logging/log_tags.md#L27)

We could think of using a --no-trunc flag, similar to docker ps --no-trunc, or leave that to the PR where we add --format (hence the second link above)

@thaJeztah sure, sounds good to me.
Thanks :)

@gigidwan any news on this?

@thaJeztah can I "dibs"?

If I understand correctly, we are going to implement the format flag in stats, right?

dibs

@ripcurld00d yes, that's the idea; that way we can keep the regular output as-is, but allow people to pick additional/other columns if desired

👍

My two cents, requiring contortion to get a 'docker stats' to return sane
names as opposed to user hostile guids defeats the spirit of this request

On Thursday, 14 July 2016, Thomas [email protected] wrote:

👍


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/docker/docker/issues/20973#issuecomment-232577820,
or mute the thread
https://github.com/notifications/unsubscribe/AAAUXcVZN_gCTAef7a9EHV-FS3XiFPhyks5qVeAQgaJpZM4Hp-TT
.

Agree, I see no reason to return ID's, and ID's and names are interchangeable as far as the API is concerned so not really anything I can see as a back-compat issue.

I'm okay personally with changing the default, but there were some concerns raised on an earlier PR: https://github.com/docker/docker/pull/21185#issuecomment-196509287

Having a --format flag would be consistent with other commands, and unblock this PR: https://github.com/docker/docker/pull/21178

We can still use ID's in the backend (for watching events or whatever), but display names.

dibs

👍

Every time I use docker stats, I have to use docker stats $(docker ps --format={{.Names}}), otherwise, I have totally no idea which container is which. And I don't think docker stats $(docker ps --format={{.Names}}) is the solution, because it's static container list. I have to stop and rerun this command if I remove a container, or run a new container.

It make more sense if there is a name column in the docker stats by default.

Just came across this myself. Very much agree with @twang2218. Would love this feature by default!

Meanwhile this alias can cover what @twang2218 said:

alias ds='while true; do TEXT=$(docker stats --no-stream $(docker ps --format={{.Names}})); sleep 0.1; clear; echo "$TEXT"; done'

@thaJeztah

27797 was merged, I think you can close it.

This is not solved. OP asked for a solution that works without having to specify the complete format manually IMHO.

The added --format option is even more inconvenient than running the ridiculous docker stats $(docker ps --format={{.Names}})

@rmoriz you can set your custom format in ~/.docker/config.json so that you don't have to type it when using docker stats. We may change the default at some point, but decided not to at this point

I come here twice a day to copy and paste this stupid command docker stats $(docker ps --format={{.Names}})

@mjaggard open the file ~/.docker/config.json in an editor, and modify it to look like this (where "other-option-1" and "other-option-2" are existing configuration options you may have in that file);

{
  "other-option-1":"foo",
  "other-option-2":"bar",
  "statsFormat": "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"
}

After that, Names will be used by default. You can add/remove other columns by changing the template, valid options can be found here: https://docs.docker.com/engine/reference/commandline/stats/#formatting

How often does one care about seeing the CPU of a container by ID? Do people just memorize their container IDs?

I'd expect both IDs and names from docker stats by default if only because docker ps already gives you both.

Good new everyone: I decided to open a PR for changing the default format to show CONTAINER ID (truncated) and NAME by default, and add a --no-trunc flag to docker stats. The PR was just merged, so will be in an upcoming Docker release (17.10 or 17.11); https://github.com/docker/cli/pull/565

Was this page helpful?
0 / 5 - 0 ratings