From 62f67cf2c22237b1866a202e3b7ba0fc2c1598ac Mon Sep 17 00:00:00 2001 From: Emile Date: Wed, 9 Oct 2019 19:47:53 +0200 Subject: moved the metrics handler to /metrics --- src/http.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/http.go b/src/http.go index 0add89e..a08845e 100644 --- a/src/http.go +++ b/src/http.go @@ -12,6 +12,7 @@ func setupHTTPServer() http.Server { r := mux.NewRouter() r.HandleFunc("/", indexHandler) + r.HandleFunc("/metrics", metricsHandler) return http.Server{ Addr: fmt.Sprintf("0.0.0.0:%d", *port), @@ -21,11 +22,20 @@ func setupHTTPServer() http.Server { // indexHandler handles the "/" endpoint func indexHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "%s", "You can find the metrics by accessing the /metrics endpoint!\n") +} + +// metricsHandler handles the "/metrics" endpoint +func metricsHandler(w http.ResponseWriter, r *http.Request) { if userFlags == nil { userFlags = make(map[string]int) } + fmt.Fprintf(w, "%s\n", "scoreboard_up 1") + for _, user := range users { - fmt.Fprintf(w, "challengesSolves{name=%s} %d\n", user, userFlags[user]) + if user != "" { + fmt.Fprintf(w, "challengesSolves{name=\"%s\"} %d\n", user, userFlags[user]) + } } } -- cgit 1.4.1