mirror of https://github.com/docker/docs.git
Merge pull request #17638 from calavera/move_net_stats_collector
Make the stats collector to collect network stats.
This commit is contained in:
commit
aff8bd178c
|
@ -8,8 +8,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/versions/v1p20"
|
"github.com/docker/docker/api/types/versions/v1p20"
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
"github.com/docker/docker/daemon/execdriver"
|
||||||
"github.com/docker/docker/pkg/version"
|
"github.com/docker/docker/pkg/version"
|
||||||
lntypes "github.com/docker/libnetwork/types"
|
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerStatsConfig holds information for configuring the runtime
|
// ContainerStatsConfig holds information for configuring the runtime
|
||||||
|
@ -45,10 +43,6 @@ func (daemon *Daemon) ContainerStats(prefixOrName string, config *ContainerStats
|
||||||
var preCPUStats types.CPUStats
|
var preCPUStats types.CPUStats
|
||||||
getStatJSON := func(v interface{}) *types.StatsJSON {
|
getStatJSON := func(v interface{}) *types.StatsJSON {
|
||||||
update := v.(*execdriver.ResourceStats)
|
update := v.(*execdriver.ResourceStats)
|
||||||
// Retrieve the nw statistics from libnetwork and inject them in the Stats
|
|
||||||
if nwStats, err := daemon.getNetworkStats(container); err == nil {
|
|
||||||
update.Stats.Interfaces = nwStats
|
|
||||||
}
|
|
||||||
ss := convertStatsToAPITypes(update.Stats)
|
ss := convertStatsToAPITypes(update.Stats)
|
||||||
ss.PreCPUStats = preCPUStats
|
ss.PreCPUStats = preCPUStats
|
||||||
ss.MemoryStats.Limit = uint64(update.MemoryLimit)
|
ss.MemoryStats.Limit = uint64(update.MemoryLimit)
|
||||||
|
@ -129,37 +123,3 @@ func (daemon *Daemon) ContainerStats(prefixOrName string, config *ContainerStats
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) getNetworkStats(c *Container) ([]*libcontainer.NetworkInterface, error) {
|
|
||||||
var list []*libcontainer.NetworkInterface
|
|
||||||
|
|
||||||
sb, err := daemon.netController.SandboxByID(c.NetworkSettings.SandboxID)
|
|
||||||
if err != nil {
|
|
||||||
return list, err
|
|
||||||
}
|
|
||||||
|
|
||||||
stats, err := sb.Statistics()
|
|
||||||
if err != nil {
|
|
||||||
return list, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert libnetwork nw stats into libcontainer nw stats
|
|
||||||
for ifName, ifStats := range stats {
|
|
||||||
list = append(list, convertLnNetworkStats(ifName, ifStats))
|
|
||||||
}
|
|
||||||
|
|
||||||
return list, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func convertLnNetworkStats(name string, stats *lntypes.InterfaceStatistics) *libcontainer.NetworkInterface {
|
|
||||||
n := &libcontainer.NetworkInterface{Name: name}
|
|
||||||
n.RxBytes = stats.RxBytes
|
|
||||||
n.RxPackets = stats.RxPackets
|
|
||||||
n.RxErrors = stats.RxErrors
|
|
||||||
n.RxDropped = stats.RxDropped
|
|
||||||
n.TxBytes = stats.TxBytes
|
|
||||||
n.TxPackets = stats.TxPackets
|
|
||||||
n.TxErrors = stats.TxErrors
|
|
||||||
n.TxDropped = stats.TxDropped
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ import (
|
||||||
"github.com/docker/docker/daemon/execdriver"
|
"github.com/docker/docker/daemon/execdriver"
|
||||||
derr "github.com/docker/docker/errors"
|
derr "github.com/docker/docker/errors"
|
||||||
"github.com/docker/docker/pkg/pubsub"
|
"github.com/docker/docker/pkg/pubsub"
|
||||||
|
lntypes "github.com/docker/libnetwork/types"
|
||||||
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
"github.com/opencontainers/runc/libcontainer/system"
|
"github.com/opencontainers/runc/libcontainer/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -118,6 +120,11 @@ func (s *statsCollector) run() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
stats.SystemUsage = systemUsage
|
stats.SystemUsage = systemUsage
|
||||||
|
|
||||||
|
// Retrieve the nw statistics from libnetwork and inject them in the Stats
|
||||||
|
if nwStats, err := s.getNetworkStats(pair.container); err == nil {
|
||||||
|
stats.Interfaces = nwStats
|
||||||
|
}
|
||||||
pair.publisher.Publish(stats)
|
pair.publisher.Publish(stats)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,3 +177,37 @@ func (s *statsCollector) getSystemCPUUsage() (uint64, error) {
|
||||||
}
|
}
|
||||||
return 0, derr.ErrorCodeBadStatFormat
|
return 0, derr.ErrorCodeBadStatFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *statsCollector) getNetworkStats(c *Container) ([]*libcontainer.NetworkInterface, error) {
|
||||||
|
var list []*libcontainer.NetworkInterface
|
||||||
|
|
||||||
|
sb, err := c.daemon.netController.SandboxByID(c.NetworkSettings.SandboxID)
|
||||||
|
if err != nil {
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
|
||||||
|
stats, err := sb.Statistics()
|
||||||
|
if err != nil {
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert libnetwork nw stats into libcontainer nw stats
|
||||||
|
for ifName, ifStats := range stats {
|
||||||
|
list = append(list, convertLnNetworkStats(ifName, ifStats))
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertLnNetworkStats(name string, stats *lntypes.InterfaceStatistics) *libcontainer.NetworkInterface {
|
||||||
|
n := &libcontainer.NetworkInterface{Name: name}
|
||||||
|
n.RxBytes = stats.RxBytes
|
||||||
|
n.RxPackets = stats.RxPackets
|
||||||
|
n.RxErrors = stats.RxErrors
|
||||||
|
n.RxDropped = stats.RxDropped
|
||||||
|
n.TxBytes = stats.TxBytes
|
||||||
|
n.TxPackets = stats.TxPackets
|
||||||
|
n.TxErrors = stats.TxErrors
|
||||||
|
n.TxDropped = stats.TxDropped
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue