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:
parent
cbd37fba86
commit
50106c7490
30
api_temp.go
30
api_temp.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue