New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker stats live container resource metrics #9984
Conversation
@@ -97,6 +97,7 @@ func init() { | |||
{"save", "Save an image to a tar archive"}, | |||
{"search", "Search for an image on the Docker Hub"}, | |||
{"start", "Start a stopped container"}, | |||
{"stats", "Receive container stasts"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here
What about showing stats for all running containers if |
af722be
to
917b1f1
Compare
can you go up the exact number of lines and rewrite on top of it, instead of clearing the screen. (that's how we do for pull) |
@bobrik I guess it would depend on how many containers you have. You can always do docker stats `docker ps -q` |
exited containers aren't handled properly |
@vieux I think exited containers should get zeroed out then when they start again you start getting metrics. What do you think of that functionality ? |
func (s *statsCollector) start() { | ||
go func() { | ||
for _ = range time.Tick(s.interval) { | ||
log.Debugf("starting collection of container stats") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this debug is printed way too often, I feel like the -D
is useless with it.
cpuPercent = calcuateCpuPercent(previousCpu, previousSystem, v) | ||
} | ||
start = false | ||
d := data[name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with map
concurrency guarantees, but is that a safe thing to do without locking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no ;)
ThrottledTime uint64 `json:"throttled_time,omitempty"` | ||
} | ||
|
||
// All CPU stats are aggregate since container inception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/aggregate/aggregated
@crosbymichael I mean the cli is hanging and waiting for |
@@ -49,6 +49,9 @@ func (daemon *Daemon) ContainerRm(job *engine.Job) engine.Status { | |||
} | |||
|
|||
if container != nil { | |||
// stop collection of stats for the container reguardless |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/reguardless/regardless/
I got a panic when trying to delete a container:
|
Fixed the panic |
fd5fe65
to
43c5038
Compare
@vieux fixed the issue where you request stats for a non running container, it will go ahead and add it then when it's started you see the stats start flowing in. |
|
||
func calcuateCpuPercent(previousCpu, previousSystem uint64, v *stats.Stats) float64 { | ||
cpuPercent := 0.0 | ||
cpuDelta := float64(v.CpuStats.CpuUsage.TotalUsage) - float64(previousCpu) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check previousCpu < TotalUsage
, otherwise negative numbers appear on container restart.
@crosbymichael It's like what @LK4D4 said. We may want to get the one-time status of containers. |
I noticed if I run |
@ekuric This is expected $(docker ps -q) is only run once, and is only pulling those ids. |
@cpuguy83 ah,yes, thank you,sorry for noise |
Thanks! This is a great addition. Are there plans to let users control the frequency with which they can extract stats data from the api endpoint? 1 second may be too aggressive when there are a lot of containers running on a host. |
The CPU usage % seem to be stuck at 0% for me. Being able to monitor the growing size of a running container and its disk I/O would also be very useful. |
Thanks for this new feature. Works like a charm |
@usertaken if you want disk IO for monitoring hit the API, the CLI is very dumbed down for a quick and simple view. If you are using this for monitoring use the api |
very nice stuff! |
I'm also waiting for the option like --count or something that just capture the stats once. It will be very useful when getting remote parameter. |
+1 to the count option. I'd love to create a New Relic plugin for this data but there is a lot of extra work I have to do if I don't have control over the polling interval (plus the consumption of a continuous stream is much more involved process) |
For me, I would like to get the current stats of the containers and no need to return the whole stream. It would be great to support this feature 😃 |
I agree :) |
+1 for a simply way of just getting current stats as opposed to subscribing and disconnecting |
@SvenDowideit API docs need a bit more info on what the cpu numbers mean and how you go about converting them to % cpu |
+1 for just getting current numbers without subscription. @crosbymichael I can create a separate issue. |
+1 :) |
👍 |
Stats are nice. Thanks. Here's a one-liner that does what you would expect
However, the flicker is distinctly unpleasant. |
I love and appreciate the concept and current possibilities, however I have some thoughts: I don't understand why it is repeating (or why it doesn't have the count flag). I could eg. use 'watch' and its features to show me a constant update if I want that. I also find it hard to imagine writing a simple script to parse the json data if it has to be running forever. I'd rather query once a minute and send those stats to graphite (just an example), but I don't see how I could accomplish this in a simple way (someone has any thoughts?) I would also appreciate the presence of an 'all' option, especially for the json-part (where you would have to run several queries to get all container data) |
+1 for a count option. |
Please stop adding new feature requests to a closed/merged PR. If you have an enhancement/feature request, open a new issue. For those looking for a "count" option; there is a PR that implements a |
This PR allows you to receive live container metrics for your containers. You can use the
docker stats <containers...>
cli command to get a live top like interface. This only displays a few of the metrics available.For people who require more information they can subscribe to the container's stats stream and receive more information such as blkio information.
GET
/v1/containers/redis/stats