Пример #1
0
func (dc *DockerContainers) Run() error {
	containers, err := libdocker.AllInspectedContainers(dc.DockerHost)
	if err != nil {
		return nil
	}

	for _, container := range containers {
		if container.ID != "" && container.NiceImageName != "" {
			dc.Data[container.NiceImageName+"-"+container.ID] = container
		}
	}

	return nil
}
// Run gathers cgroup memory information from cgroup itself.
// If you use container via systemd.slice, you could use
// containerid = docker-<container id>.scope and base=/sys/fs/cgroup/memory/system.slice/
func (m *DockerContainersNetDev) Run() error {
	containers, err := libdocker.AllInspectedContainers(m.DockerHost)
	if err != nil {
		return nil
	}

	for _, container := range containers {
		if container.ID != "" && container.State.Running {
			pid := container.State.Pid

			data, err := linuxproc.ReadNetworkStat(fmt.Sprintf("/proc/%v/net/dev", pid))
			if err == nil {
				m.Data[container.NiceImageName+"-"+container.ID] = make(map[string]linuxproc.NetworkStat)

				for _, perIface := range data {
					m.Data[container.NiceImageName+"-"+container.ID][perIface.Iface] = perIface
				}
			}
		}
	}

	return nil
}