Example #1
0
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
	stats, err := libcontainer.GetStats(self.cgroupPaths, &self.libcontainerState)
	if err != nil {
		return stats, err
	}

	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	// Fill in network stats for root.
	nd, err := self.GetRootNetworkDevices()
	if err != nil {
		return stats, err
	}
	if len(nd) != 0 {
		// ContainerStats only reports stat for one network device.
		// TODO(rjnagal): Handle multiple physical network devices.
		stats.Network, err = sysinfo.GetNetworkStats(nd[0].Name)
		if err != nil {
			return stats, err
		}
	}
	return stats, nil
}
Example #2
0
func (handler *rktContainerHandler) GetStats() (*info.ContainerStats, error) {
	stats, err := libcontainer.GetStats(handler.cgroupManager, handler.rootFs, handler.pid, handler.ignoreMetrics)
	if err != nil {
		return stats, err
	}

	// Get filesystem stats.
	err = handler.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
Example #3
0
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
	stats, err := libcontainer.GetStats(self.cgroupManager, self.rootFs, os.Getpid())
	if err != nil {
		return stats, err
	}

	// Get filesystem stats.
	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
Example #4
0
func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err error) {
	state, err := self.readLibcontainerState()
	if err != nil {
		return nil, err
	}

	stats, err = containerLibcontainer.GetStats(self.cgroupPaths, state)
	if err != nil {
		return stats, err
	}
	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
// TODO(vmarmol): Get from libcontainer API instead of cgroup manager when we don't have to support older Dockers.
func (self *dockerContainerHandler) GetStats() (*info.ContainerStats, error) {
	config, err := self.readLibcontainerConfig()
	if err != nil {
		return nil, err
	}

	var networkInterfaces []string
	if len(config.Networks) > 0 {
		// ContainerStats only reports stat for one network device.
		// TODO(vmarmol): Handle multiple physical network devices.
		for _, n := range config.Networks {
			// Take the first non-loopback.
			if n.Type != "loopback" {
				networkInterfaces = []string{n.HostInterfaceName}
				break
			}
		}
	}
	stats, err := containerLibcontainer.GetStats(self.cgroupManager, networkInterfaces)
	if err != nil {
		return stats, err
	}

	// TODO(rjnagal): Remove the conversion when network stats are read from libcontainer.
	net := stats.Network
	// Ingress for host veth is from the container.
	// Hence tx_bytes stat on the host veth is actually number of bytes received by the container.
	stats.Network.RxBytes = net.TxBytes
	stats.Network.RxPackets = net.TxPackets
	stats.Network.RxErrors = net.TxErrors
	stats.Network.RxDropped = net.TxDropped
	stats.Network.TxBytes = net.RxBytes
	stats.Network.TxPackets = net.RxPackets
	stats.Network.TxErrors = net.RxErrors
	stats.Network.TxDropped = net.RxDropped

	// Get filesystem stats.
	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
Example #6
0
// TODO(vmarmol): Get from libcontainer API instead of cgroup manager when we don't have to support older Dockers.
func (self *dockerContainerHandler) GetStats() (*info.ContainerStats, error) {
	stats, err := containerlibcontainer.GetStats(self.cgroupManager, self.rootFs, self.pid, self.ignoreMetrics)
	if err != nil {
		return stats, err
	}
	// Clean up stats for containers that don't have their own network - this
	// includes containers running in Kubernetes pods that use the network of the
	// infrastructure container. This stops metrics being reported multiple times
	// for each container in a pod.
	if !self.needNet() {
		stats.Network = info.NetworkStats{}
	}

	// Get filesystem stats.
	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
Example #7
0
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
	nd, err := self.GetRootNetworkDevices()
	if err != nil {
		return new(info.ContainerStats), err
	}
	networkInterfaces := make([]string, len(nd))
	for i := range nd {
		networkInterfaces[i] = nd[i].Name
	}
	stats, err := libcontainer.GetStats(self.cgroupManager, networkInterfaces)
	if err != nil {
		return stats, err
	}

	// Get filesystem stats.
	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
Example #8
0
func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err error) {
	if self.isDockerRoot() {
		return &info.ContainerStats{}, nil
	}
	config, err := self.readLibcontainerConfig()
	if err != nil {
		if err == fileNotFound {
			glog.Errorf("Libcontainer config not found for container %q", self.name)
			return &info.ContainerStats{}, nil
		}
		return
	}
	state, err := self.readLibcontainerState()
	if err != nil {
		if err == fileNotFound {
			glog.Errorf("Libcontainer state not found for container %q", self.name)
			return &info.ContainerStats{}, nil
		}
		return
	}

	return containerLibcontainer.GetStats(config, state)
}
Example #9
0
// TODO(vmarmol): Get from libcontainer API instead of cgroup manager when we don't have to support older Dockers.
func (self *dockerContainerHandler) GetStats() (*info.ContainerStats, error) {
	config, err := self.readLibcontainerConfig()
	if err != nil {
		return nil, err
	}

	var networkInterfaces []string
	if len(config.Networks) > 0 {
		// ContainerStats only reports stat for one network device.
		// TODO(vmarmol): Handle multiple physical network devices.
		for _, n := range config.Networks {
			// Take the first non-loopback.
			if n.Type != "loopback" {
				networkInterfaces = []string{n.HostInterfaceName}
				break
			}
		}
	}
	stats, err := containerLibcontainer.GetStats(self.cgroupManager, networkInterfaces)
	if err != nil {
		return stats, err
	}

	// TODO(rjnagal): Remove the conversion when network stats are read from libcontainer.
	convertInterfaceStats(&stats.Network.InterfaceStats)
	for i := range stats.Network.Interfaces {
		convertInterfaceStats(&stats.Network.Interfaces[i])
	}

	// Get filesystem stats.
	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
	var networkInterfaces []string
	nd, err := self.GetRootNetworkDevices()
	if err != nil {
		return new(info.ContainerStats), err
	}
	if len(nd) != 0 {
		// ContainerStats only reports stat for one network device.
		// TODO(rjnagal): Handle multiple physical network devices.
		networkInterfaces = []string{nd[0].Name}
	}
	stats, err := libcontainer.GetStats(self.cgroupManager, networkInterfaces)
	if err != nil {
		return stats, err
	}

	// Get filesystem stats.
	err = self.getFsStats(stats)
	if err != nil {
		return stats, err
	}

	return stats, nil
}
Example #11
0
func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err error) {
	if self.isDockerRoot() {
		return &info.ContainerStats{}, nil
	}
	state, err := self.readLibcontainerState()
	if err != nil {
		if err == fileNotFound {
			glog.Errorf("Libcontainer state not found for container %q", self.name)
			return &info.ContainerStats{}, nil
		}
		return
	}

	stats, err = containerLibcontainer.GetStats(&self.cgroup, state)
	if err != nil {
		return
	}
	err = self.getFsStats(stats)
	if err != nil {
		return
	}

	return stats, nil
}
Example #12
0
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
	state := dockerlibcontainer.State{}
	if self.networkInterface != nil {
		state = dockerlibcontainer.State{
			NetworkState: network.NetworkState{
				VethHost:  self.networkInterface.VethHost,
				VethChild: self.networkInterface.VethChild,
				NsPath:    "unknown",
			},
		}
	}

	stats, err := libcontainer.GetStats(self.cgroup, &state)
	if err != nil {
		return nil, err
	}

	err = self.getFsStats(stats)
	if err != nil {
		return nil, err
	}

	return stats, nil
}