Skip to content

Commit

Permalink
Merge pull request docker#21342 from tonistiigi/cleanup-libcontainer
Browse files Browse the repository at this point in the history
Convert libnetwork stats directly to api types
  • Loading branch information
Arnaud Porterie committed Mar 21, 2016
2 parents be8459c + f25d9f0 commit 2a4c970
Show file tree
Hide file tree
Showing 73 changed files with 19 additions and 10,645 deletions.
63 changes: 19 additions & 44 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ import (
"github.com/docker/go-connections/nat"
"github.com/docker/libnetwork"
nwconfig "github.com/docker/libnetwork/config"
lntypes "github.com/docker/libnetwork/types"
"github.com/docker/libtrust"
"github.com/opencontainers/runc/libcontainer"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -1528,50 +1526,40 @@ func (daemon *Daemon) GetContainerStats(container *container.Container) (*types.
return nil, err
}

// Retrieve the nw statistics from libnetwork and inject them in the Stats
var nwStats []*libcontainer.NetworkInterface
if nwStats, err = daemon.getNetworkStats(container); err != nil {
if stats.Networks, err = daemon.getNetworkStats(container); err != nil {
return nil, err
}

stats.Networks = make(map[string]types.NetworkStats)
for _, iface := range nwStats {
// For API Version >= 1.21, the original data of network will
// be returned.
stats.Networks[iface.Name] = types.NetworkStats{
RxBytes: iface.RxBytes,
RxPackets: iface.RxPackets,
RxErrors: iface.RxErrors,
RxDropped: iface.RxDropped,
TxBytes: iface.TxBytes,
TxPackets: iface.TxPackets,
TxErrors: iface.TxErrors,
TxDropped: iface.TxDropped,
}
}

return stats, nil
}

func (daemon *Daemon) getNetworkStats(c *container.Container) ([]*libcontainer.NetworkInterface, error) {
var list []*libcontainer.NetworkInterface

func (daemon *Daemon) getNetworkStats(c *container.Container) (map[string]types.NetworkStats, error) {
sb, err := daemon.netController.SandboxByID(c.NetworkSettings.SandboxID)
if err != nil {
return list, err
return nil, err
}

stats, err := sb.Statistics()
lnstats, err := sb.Statistics()
if err != nil {
return list, err
return nil, err
}

// Convert libnetwork nw stats into libcontainer nw stats
for ifName, ifStats := range stats {
list = append(list, convertLnNetworkStats(ifName, ifStats))
stats := make(map[string]types.NetworkStats)
// Convert libnetwork nw stats into engine-api stats
for ifName, ifStats := range lnstats {
stats[ifName] = types.NetworkStats{
RxBytes: ifStats.RxBytes,
RxPackets: ifStats.RxPackets,
RxErrors: ifStats.RxErrors,
RxDropped: ifStats.RxDropped,
TxBytes: ifStats.TxBytes,
TxPackets: ifStats.TxPackets,
TxErrors: ifStats.TxErrors,
TxDropped: ifStats.TxDropped,
}
}

return list, nil
return stats, nil
}

// newBaseContainer creates a new container with its initial
Expand Down Expand Up @@ -1675,19 +1663,6 @@ func (daemon *Daemon) reloadClusterDiscovery(config *Config) error {
return 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
}

func validateID(id string) error {
if id == "" {
return fmt.Errorf("Invalid empty id")
Expand Down
14 changes: 0 additions & 14 deletions daemon/stats_freebsd.go

This file was deleted.

187 changes: 0 additions & 187 deletions vendor/src/github.com/coreos/go-systemd/dbus/dbus.go

This file was deleted.

Loading

0 comments on commit 2a4c970

Please sign in to comment.