Ejemplo n.º 1
0
func main() {
	flag.Parse()

	storageDriver, err := NewStorageDriver(*argDbDriver)
	if err != nil {
		glog.Fatalf("Failed to connect to database: %s", err)
	}

	containerManager, err := manager.New(storageDriver)
	if err != nil {
		glog.Fatalf("Failed to create a Container Manager: %s", err)
	}

	// Register Docker.
	if err := docker.Register(containerManager); err != nil {
		glog.Errorf("Docker registration failed: %v.", err)
	}

	// Register the raw driver.
	if err := raw.Register(containerManager); err != nil {
		glog.Fatalf("raw registration failed: %v.", err)
	}

	// Handler for static content.
	http.HandleFunc(static.StaticResource, func(w http.ResponseWriter, r *http.Request) {
		err := static.HandleRequest(w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Register API handler.
	if err := api.RegisterHandlers(containerManager); err != nil {
		glog.Fatalf("failed to register API handlers: %s", err)
	}

	// Redirect / to containers page.
	http.Handle("/", http.RedirectHandler(pages.ContainersPage, http.StatusTemporaryRedirect))

	// Register the handler for the containers page.
	http.HandleFunc(pages.ContainersPage, func(w http.ResponseWriter, r *http.Request) {
		err := pages.ServerContainersPage(containerManager, w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	defer glog.Flush()

	go func() {
		glog.Fatal(containerManager.Start())
	}()

	glog.Infof("Starting cAdvisor version: %q", info.VERSION)
	glog.Infof("About to serve on port ", *argPort)

	addr := fmt.Sprintf(":%v", *argPort)

	glog.Fatal(http.ListenAndServe(addr, nil))
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	storage := memory.New(*argSampleSize, *argHistoryDuration)
	// TODO(monnand): Add stats writer for manager
	containerManager, err := manager.New(storage)
	if err != nil {
		log.Fatalf("Failed to create a Container Manager: %s", err)
	}

	if err := lmctfy.Register("/"); err != nil {
		log.Printf("lmctfy registration failed: %v.", err)
		log.Print("Running in docker only mode.")
		if err := docker.Register(containerManager, "/"); err != nil {
			log.Printf("Docker registration failed: %v.", err)
			log.Fatalf("Unable to continue without docker or lmctfy.")
		}
	}

	if err := docker.Register(containerManager, "/docker"); err != nil {
		// Ignore this error because we should work with lmctfy only
		log.Printf("Docker registration failed: %v.", err)
		log.Print("Running in lmctfy only mode.")
	}

	// Handler for static content.
	http.HandleFunc(static.StaticResource, func(w http.ResponseWriter, r *http.Request) {
		err := static.HandleRequest(w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Handler for the API.
	http.HandleFunc(api.ApiResource, func(w http.ResponseWriter, r *http.Request) {
		err := api.HandleRequest(containerManager, w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Redirect / to containers page.
	http.Handle("/", http.RedirectHandler(pages.ContainersPage, http.StatusTemporaryRedirect))

	// Register the handler for the containers page.
	http.HandleFunc(pages.ContainersPage, func(w http.ResponseWriter, r *http.Request) {
		err := pages.ServerContainersPage(containerManager, w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	go containerManager.Start()

	log.Printf("Starting cAdvisor version: %q", info.VERSION)
	log.Print("About to serve on port ", *argPort)

	addr := fmt.Sprintf(":%v", *argPort)
	log.Fatal(http.ListenAndServe(addr, nil))
}
Ejemplo n.º 3
0
func staticHandlerNoAuth(w http.ResponseWriter, r *http.Request) {
	err := static.HandleRequest(w, r.URL)
	if err != nil {
		fmt.Fprintf(w, "%s", err)
	}
}
Ejemplo n.º 4
0
func staticHandler(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
	err := static.HandleRequest(w, r.URL)
	if err != nil {
		fmt.Fprintf(w, "%s", err)
	}
}
Ejemplo n.º 5
0
func main() {
	flag.Parse()
	// XXX(dengnan): Should we allow users to specify which sampler they want to use?
	container.SetStatsParameter(&container.StatsParameter{
		Sampler:     "uniform",
		NumSamples:  *argSampleSize,
		ResetPeriod: *argResetPeriod,
	})
	containerManager, err := manager.New()
	if err != nil {
		log.Fatalf("Failed to create a Container Manager: %s", err)
	}

	if err := lmctfy.Register("/"); err != nil {
		log.Printf("lmctfy registration failed: %v.", err)
		log.Print("Running in docker only mode.")
		if err := docker.Register(containerManager, "/"); err != nil {
			log.Printf("Docker registration failed: %v.", err)
			log.Fatalf("Unable to continue without docker or lmctfy.")
		}
	}

	if err := docker.Register(containerManager, "/docker"); err != nil {
		// Ignore this error because we should work with lmctfy only
		log.Printf("Docker registration failed: %v.", err)
		log.Print("Running in lmctfy only mode.")
	}

	// Handler for static content.
	http.HandleFunc(static.StaticResource, func(w http.ResponseWriter, r *http.Request) {
		err := static.HandleRequest(w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Handler for the API.
	http.HandleFunc(api.ApiResource, func(w http.ResponseWriter, r *http.Request) {
		err := api.HandleRequest(containerManager, w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Redirect / to containers page.
	http.Handle("/", http.RedirectHandler(pages.ContainersPage, http.StatusTemporaryRedirect))

	// Register the handler for the containers page.
	http.HandleFunc(pages.ContainersPage, func(w http.ResponseWriter, r *http.Request) {
		err := pages.ServerContainersPage(containerManager, w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	go containerManager.Start()

	log.Print("About to serve on port ", *argPort)

	addr := fmt.Sprintf(":%v", *argPort)
	log.Fatal(http.ListenAndServe(addr, nil))
}
Ejemplo n.º 6
0
func main() {
	flag.Parse()

	storageDriver, err := NewStorageDriver(*argDbDriver)
	if err != nil {
		log.Fatalf("Failed to connect to database: %s", err)
	}

	containerManager, err := manager.New(storageDriver)
	if err != nil {
		log.Fatalf("Failed to create a Container Manager: %s", err)
	}

	// Register lmctfy for the root if allowed and available.
	registeredRoot := false
	if *argAllowLmctfy {
		if err := lmctfy.Register("/"); err != nil {
			log.Printf("lmctfy registration failed: %v.", err)
			log.Print("Running in docker only mode.")
		} else {
			registeredRoot = true
		}
	}

	// Register Docker for root if we were unable to register lmctfy.
	if !registeredRoot {
		if err := docker.Register(containerManager, "/"); err != nil {
			log.Printf("Docker registration failed: %v.", err)
			log.Fatalf("Unable to continue without root handler.")
		}
	}

	// Register Docker for all Docker containers.
	if err := docker.Register(containerManager, "/docker"); err != nil {
		// Ignore this error because we should work with lmctfy only
		log.Printf("Docker registration failed: %v.", err)
		log.Print("Running in lmctfy only mode.")
	}

	// Handler for static content.
	http.HandleFunc(static.StaticResource, func(w http.ResponseWriter, r *http.Request) {
		err := static.HandleRequest(w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Handler for the API.
	http.HandleFunc(api.ApiResource, func(w http.ResponseWriter, r *http.Request) {
		err := api.HandleRequest(containerManager, w, r)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	// Redirect / to containers page.
	http.Handle("/", http.RedirectHandler(pages.ContainersPage, http.StatusTemporaryRedirect))

	// Register the handler for the containers page.
	http.HandleFunc(pages.ContainersPage, func(w http.ResponseWriter, r *http.Request) {
		err := pages.ServerContainersPage(containerManager, w, r.URL)
		if err != nil {
			fmt.Fprintf(w, "%s", err)
		}
	})

	go containerManager.Start()

	log.Printf("Starting cAdvisor version: %q", info.VERSION)
	log.Print("About to serve on port ", *argPort)

	addr := fmt.Sprintf(":%v", *argPort)
	log.Fatal(http.ListenAndServe(addr, nil))
}