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 (
"github.com/docker/libcontainer/cgroups/fs"
"github.com/docker/libcontainer/cgroups/systemd"
"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.
// Returns all available stats for the given container.
func GetStats(container *Config, state *State) (*ContainerStats, error) {
var containerStats ContainerStats
stats, err := fs.GetStats(container.Cgroups)
if err != nil {
return &containerStats, err
}
containerStats.CgroupStats = stats
networkStats, err := network.GetStats(&state.NetworkState)
if err != nil {
return &containerStats, err
}
containerStats.NetworkStats = networkStats
var (
err error
stats = &ContainerStats{}
)
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
theConn *systemd1.Conn
hasStartTransientUnit bool
subsystems = map[string]subsystem{
subsystems = map[string]subsystem{
"devices": &fs.DevicesGroup{},
"memory": &fs.MemoryGroup{},
"cpu": &fs.CpuGroup{},
@ -417,15 +417,14 @@ func getUnitName(c *cgroups.Cgroup) string {
* http://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/#readingaccountinginformation.
*/
func GetStats(c *cgroups.Cgroup) (*cgroups.Stats, error) {
var subsystemPath string
var err error
stats := cgroups.NewStats()
for sysname, sys := range subsystems {
if subsystemPath, err = getSubsystemPath(c, sysname); err != nil {
subsystemPath, err := getSubsystemPath(c, sysname)
if err != nil {
return nil, err
}
if err := sys.GetStats(subsystemPath, stats); err != nil {
return nil, err
}