Exemplo n.º 1
0
func (msrv *MetricsService) RegisterHandler() {
	handler := func(h func(http.ResponseWriter, *http.Request)) http.Handler {
		return http_utils.CompressionHandler{
			Handler: http.HandlerFunc(h),
		}
	}
	exp.Handle("/api/query", handler(msrv.Query))
	exp.Handle("/api/query_range", handler(msrv.QueryRange))
	exp.Handle("/api/metrics", handler(msrv.Metrics))
	exp.Handle("/api/targets", handler(msrv.SetTargets))
}
Exemplo n.º 2
0
func (w WebService) ServeForever() error {
	exp.Handle("/favicon.ico", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		http.Error(w, "", 404)
	}))

	// TODO(julius): This will need to be rewritten once the exp package provides
	// the coarse mux behaviors via a wrapper function.
	exp.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
	exp.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
	exp.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
	exp.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))

	exp.Handle("/", w.StatusHandler)
	exp.Handle("/databases", w.DatabasesHandler)
	exp.Handle("/alerts", w.AlertsHandler)
	exp.HandleFunc("/graph", graphHandler)
	exp.HandleFunc("/heap", dumpHeap)

	w.MetricsHandler.RegisterHandler()
	exp.Handle("/metrics", prometheus.DefaultHandler)
	if *useLocalAssets {
		exp.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
	} else {
		exp.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
	}

	if *userAssetsPath != "" {
		exp.Handle("/user/", http.StripPrefix("/user/", http.FileServer(http.Dir(*userAssetsPath))))
	}

	if *enableQuit {
		exp.HandleFunc("/-/quit", w.quitHandler)
	}

	glog.Info("listening on ", *listenAddress)

	return http.ListenAndServe(*listenAddress, exp.DefaultCoarseMux)
}