mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #16142 from cpuguy83/stats_pass_container
Don't lookup container 4 times for stats
This commit is contained in:
commit
451f4d0d3b
3 changed files with 8 additions and 21 deletions
|
@ -103,7 +103,7 @@ func (s *Server) getContainersStats(version version.Version, w http.ResponseWrit
|
|||
Stop: closeNotifier,
|
||||
}
|
||||
|
||||
return s.daemon.ContainerStats(vars["name"], config)
|
||||
return s.daemon.ContainerStats(container, config)
|
||||
}
|
||||
|
||||
func (s *Server) getContainersLogs(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
|
|
@ -886,20 +886,12 @@ func (daemon *Daemon) stats(c *Container) (*execdriver.ResourceStats, error) {
|
|||
return daemon.execDriver.Stats(c.ID)
|
||||
}
|
||||
|
||||
func (daemon *Daemon) subscribeToContainerStats(name string) (chan interface{}, error) {
|
||||
c, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func (daemon *Daemon) subscribeToContainerStats(c *Container) (chan interface{}, error) {
|
||||
ch := daemon.statsCollector.collect(c)
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) unsubscribeToContainerStats(name string, ch chan interface{}) error {
|
||||
c, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (daemon *Daemon) unsubscribeToContainerStats(c *Container, ch chan interface{}) error {
|
||||
daemon.statsCollector.unsubscribe(c, ch)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ type ContainerStatsConfig struct {
|
|||
|
||||
// ContainerStats writes information about the container to the stream
|
||||
// given in the config object.
|
||||
func (daemon *Daemon) ContainerStats(name string, config *ContainerStatsConfig) error {
|
||||
updates, err := daemon.subscribeToContainerStats(name)
|
||||
func (daemon *Daemon) ContainerStats(container *Container, config *ContainerStatsConfig) error {
|
||||
updates, err := daemon.subscribeToContainerStats(container)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func (daemon *Daemon) ContainerStats(name string, config *ContainerStatsConfig)
|
|||
getStat := func(v interface{}) *types.Stats {
|
||||
update := v.(*execdriver.ResourceStats)
|
||||
// Retrieve the nw statistics from libnetwork and inject them in the Stats
|
||||
if nwStats, err := daemon.getNetworkStats(name); err == nil {
|
||||
if nwStats, err := daemon.getNetworkStats(container); err == nil {
|
||||
update.Stats.Interfaces = nwStats
|
||||
}
|
||||
ss := convertStatsToAPITypes(update.Stats)
|
||||
|
@ -48,7 +48,7 @@ func (daemon *Daemon) ContainerStats(name string, config *ContainerStatsConfig)
|
|||
|
||||
enc := json.NewEncoder(config.OutStream)
|
||||
|
||||
defer daemon.unsubscribeToContainerStats(name, updates)
|
||||
defer daemon.unsubscribeToContainerStats(container, updates)
|
||||
|
||||
noStreamFirstFrame := true
|
||||
for {
|
||||
|
@ -78,14 +78,9 @@ func (daemon *Daemon) ContainerStats(name string, config *ContainerStatsConfig)
|
|||
}
|
||||
}
|
||||
|
||||
func (daemon *Daemon) getNetworkStats(name string) ([]*libcontainer.NetworkInterface, error) {
|
||||
func (daemon *Daemon) getNetworkStats(c *Container) ([]*libcontainer.NetworkInterface, error) {
|
||||
var list []*libcontainer.NetworkInterface
|
||||
|
||||
c, err := daemon.Get(name)
|
||||
if err != nil {
|
||||
return list, err
|
||||
}
|
||||
|
||||
sb, err := daemon.netController.SandboxByID(c.NetworkSettings.SandboxID)
|
||||
if err != nil {
|
||||
return list, err
|
||||
|
|
Loading…
Reference in a new issue