Ejemplo n.º 1
0
// Register root container before running this function!
func Register(factory info.MachineInfoFactory, paths ...string) error {
	client, err := docker.NewClient(*argDockerEndpoint)
	if err != nil {
		return fmt.Errorf("unable to communicate with docker daemon: %v", err)
	}
	if version, err := client.Version(); err != nil {
		return fmt.Errorf("unable to communicate with docker daemon: %v", err)
	} else {
		expected_version := []int{0, 11, 1}
		version_string := version.Get("Version")
		version, err := parseDockerVersion(version_string)
		if err != nil {
			return fmt.Errorf("Couldn't parse docker version: %v", err)
		}
		for index, number := range version {
			if number > expected_version[index] {
				break
			} else if number < expected_version[index] {
				return fmt.Errorf("cAdvisor requires docker version above %v but we have found version %v reported as \"%v\"", expected_version, version, version_string)
			}
		}
	}
	f := &dockerFactory{
		machineInfoFactory: factory,
	}
	cf := container.AddStatsSummaryToFactory(f)
	for _, p := range paths {
		if p != "/" && p != "/docker" {
			return fmt.Errorf("%v cannot be managed by docker", p)
		}
		container.RegisterContainerHandlerFactory(p, cf)
	}
	return nil
}
Ejemplo n.º 2
0
func Register(paths ...string) error {
	if _, err := exec.LookPath("lmctfy"); err != nil {
		return errors.New("cannot find lmctfy")
	}
	f := container.AddStatsSummaryToFactory(&lmctfyFactory{})
	for _, path := range paths {
		log.Printf("register lmctfy under %v", path)
		container.RegisterContainerHandlerFactory(path, f)
	}
	return nil
}