Fix nsinit function to get stats from systemd

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-07-11 12:00:27 -07:00
parent cbd37fba86
commit 50106c7490
2 changed files with 22 additions and 17 deletions

View File

@ -5,6 +5,7 @@ package libcontainer
import ( import (
"github.com/docker/libcontainer/cgroups/fs" "github.com/docker/libcontainer/cgroups/fs"
"github.com/docker/libcontainer/cgroups/systemd"
"github.com/docker/libcontainer/network" "github.com/docker/libcontainer/network"
) )
@ -12,17 +13,22 @@ import (
// DEPRECATED: The below portions are only to be used during the transition to the official API. // DEPRECATED: The below portions are only to be used during the transition to the official API.
// Returns all available stats for the given container. // Returns all available stats for the given container.
func GetStats(container *Config, state *State) (*ContainerStats, error) { func GetStats(container *Config, state *State) (*ContainerStats, error) {
var containerStats ContainerStats var (
stats, err := fs.GetStats(container.Cgroups) err error
if err != nil { stats = &ContainerStats{}
return &containerStats, err )
}
containerStats.CgroupStats = stats
networkStats, err := network.GetStats(&state.NetworkState)
if err != nil {
return &containerStats, err
}
containerStats.NetworkStats = networkStats
return &containerStats, nil if systemd.UseSystemd() {
stats.CgroupStats, err = systemd.GetStats(container.Cgroups)
} else {
stats.CgroupStats, err = fs.GetStats(container.Cgroups)
}
if err != nil {
return stats, err
}
stats.NetworkStats, err = network.GetStats(&state.NetworkState)
return stats, err
} }

View File

@ -32,7 +32,7 @@ var (
connLock sync.Mutex connLock sync.Mutex
theConn *systemd1.Conn theConn *systemd1.Conn
hasStartTransientUnit bool hasStartTransientUnit bool
subsystems = map[string]subsystem{ subsystems = map[string]subsystem{
"devices": &fs.DevicesGroup{}, "devices": &fs.DevicesGroup{},
"memory": &fs.MemoryGroup{}, "memory": &fs.MemoryGroup{},
"cpu": &fs.CpuGroup{}, "cpu": &fs.CpuGroup{},
@ -417,15 +417,14 @@ func getUnitName(c *cgroups.Cgroup) string {
* http://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/#readingaccountinginformation. * http://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/#readingaccountinginformation.
*/ */
func GetStats(c *cgroups.Cgroup) (*cgroups.Stats, error) { func GetStats(c *cgroups.Cgroup) (*cgroups.Stats, error) {
var subsystemPath string
var err error
stats := cgroups.NewStats() stats := cgroups.NewStats()
for sysname, sys := range subsystems { for sysname, sys := range subsystems {
if subsystemPath, err = getSubsystemPath(c, sysname); err != nil { subsystemPath, err := getSubsystemPath(c, sysname)
if err != nil {
return nil, err return nil, err
} }
if err := sys.GetStats(subsystemPath, stats); err != nil { if err := sys.GetStats(subsystemPath, stats); err != nil {
return nil, err return nil, err
} }