diff options
-rw-r--r-- | src/http.go | 12 |
1 files changed, 11 insertions, 1 deletions
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]) + } } } |