diff options
author | Emile <hanemile@protonmail.com> | 2019-10-09 19:47:53 +0200 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-10-09 19:47:53 +0200 |
commit | 62f67cf2c22237b1866a202e3b7ba0fc2c1598ac (patch) | |
tree | 238fb44728560911fc297318f830e335b3364012 /src | |
parent | de78273f080634b57cc0e0e7c3e05e3ff03d0478 (diff) |
moved the metrics handler to /metrics
Diffstat (limited to 'src')
-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]) + } } } |