Esempio n. 1
0
File: http.go Progetto: jsocol/nsq
func NewHTTPServer(context *Context) *httpServer {
	var proxy *httputil.ReverseProxy

	templates.T.Funcs(template.FuncMap{
		"commafy":        util.Commafy,
		"nanotohuman":    util.NanoSecondToHuman,
		"floatToPercent": util.FloatToPercent,
		"percSuffix":     util.PercSuffix,
		"getNodeConsistencyClass": func(node *lookupd.Producer) string {
			if node.IsInconsistent(len(context.nsqadmin.options.NSQLookupdHTTPAddresses)) {
				return "btn-warning"
			}
			return ""
		},
	})
	templates.Parse()

	if context.nsqadmin.options.ProxyGraphite {
		url, err := url.Parse(context.nsqadmin.options.GraphiteURL)
		if err != nil {
			log.Fatalf("ERROR: failed to parse --graphite-url='%s' - %s",
				context.nsqadmin.options.GraphiteURL, err.Error())
		}
		proxy = NewSingleHostReverseProxy(url, 20*time.Second)
	}

	return &httpServer{
		context:  context,
		counters: make(map[string]map[string]int64),
		proxy:    proxy,
	}
}
Esempio n. 2
0
func NewHTTPServer(ctx *Context) *httpServer {
	var proxy *httputil.ReverseProxy

	templates.T.Funcs(template.FuncMap{
		"commafy":        stringy.Commafy,
		"nanotohuman":    stringy.NanoSecondToHuman,
		"floatToPercent": stringy.FloatToPercent,
		"percSuffix":     stringy.PercSuffix,
		"getNodeConsistencyClass": func(node *lookupd.Producer) string {
			if node.IsInconsistent(len(ctx.nsqadmin.opts.NSQLookupdHTTPAddresses)) {
				return "btn-warning"
			}
			return ""
		},
	})

	templates.Parse()

	if ctx.nsqadmin.opts.ProxyGraphite {
		proxy = NewSingleHostReverseProxy(ctx.nsqadmin.graphiteURL, 20*time.Second)
	}

	return &httpServer{
		ctx:      ctx,
		counters: make(map[string]map[string]int64),
		proxy:    proxy,
	}
}
Esempio n. 3
0
func NewHTTPServer(ctx *Context) *httpServer {
	var proxy *httputil.ReverseProxy

	templates.T.Funcs(template.FuncMap{
		"commafy":        stringy.Commafy,
		"nanotohuman":    stringy.NanoSecondToHuman,
		"floatToPercent": stringy.FloatToPercent,
		"percSuffix":     stringy.PercSuffix,
		"getNodeConsistencyClass": func(node *lookupd.Producer) string {
			if node.IsInconsistent(len(ctx.nsqadmin.opts.NSQLookupdHTTPAddresses)) {
				return "btn-warning"
			}
			return ""
		},
	})

	templates.Parse()

	if ctx.nsqadmin.opts.ProxyGraphite {
		proxy = NewSingleHostReverseProxy(ctx.nsqadmin.graphiteURL, 20*time.Second)
	}

	router := httprouter.New()
	router.HandleMethodNotAllowed = true
	s := &httpServer{
		ctx:      ctx,
		counters: make(map[string]map[string]int64),
		proxy:    proxy,
		router:   router,
	}

	router.Handle("GET", "/ping", s.pingHandler)

	router.Handle("GET", "/", s.indexHandler)
	router.Handle("GET", "/nodes", s.nodesHandler)
	router.Handle("GET", "/node/:node", s.nodeHandler)
	router.Handle("GET", "/topic/:topic", s.topicHandler)
	router.Handle("GET", "/topic/:topic/:channel", s.channelHandler)
	router.Handle("GET", "/static/:asset", s.embeddedAssetHandler)
	router.Handle("GET", "/counter", s.counterHandler)
	router.Handle("GET", "/counter/data", s.counterDataHandler)
	router.Handle("GET", "/lookup", s.lookupHandler)
	router.Handle("GET", "/graphite_data", s.graphiteDataHandler)

	router.Handle("POST", "/tombstone_topic_producer", s.tombstoneTopicProducerHandler)
	router.Handle("POST", "/empty_topic", s.emptyTopicHandler)
	router.Handle("POST", "/delete_topic", s.deleteTopicHandler)
	router.Handle("POST", "/pause_topic", s.pauseTopicHandler)
	router.Handle("POST", "/unpause_topic", s.pauseTopicHandler)
	router.Handle("POST", "/empty_channel", s.emptyChannelHandler)
	router.Handle("POST", "/delete_channel", s.deleteChannelHandler)
	router.Handle("POST", "/pause_channel", s.pauseChannelHandler)
	router.Handle("POST", "/unpause_channel", s.pauseChannelHandler)
	router.Handle("POST", "/create_topic_channel", s.createTopicChannelHandler)

	if s.ctx.nsqadmin.opts.ProxyGraphite {
		router.Handler("GET", "/render", s.proxy)
	}

	return s
}