示例#1
0
func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err error) {
	if !self.isDockerContainer() {
		// Return empty stats for root containers.
		stats = new(info.ContainerStats)
		stats.Timestamp = time.Now()
		return
	}
	mi, err := self.machineInfoFactory.GetMachineInfo()
	if err != nil {
		return
	}
	parent, id, err := self.splitName()
	if err != nil {
		return
	}
	cg := &cgroups.Cgroup{
		Parent: parent,
		Name:   id,
	}

	// TODO(vmarmol): Use libcontainer's Stats() in the new API when that is ready.
	// Use systemd paths if systemd is being used.
	var s *cgroups.Stats
	if systemd.UseSystemd() {
		s, err = systemd.GetStats(cg)
	} else {
		s, err = fs.GetStats(cg)
	}
	if err != nil {
		return
	}
	stats = libcontainerToContainerStats(s, mi)
	return
}
示例#2
0
文件: api_temp.go 项目: Gandi/docker
// TODO(vmarmol): Complete Stats() in final libcontainer API and move users to that.
// 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 (
		err   error
		stats = &ContainerStats{}
	)

	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
}